Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UPdate command error quotes? 2

Status
Not open for further replies.

clivehenderson

IS-IT--Management
Nov 2, 2002
66
0
0
GB
Hi, hope someone can help


If I assign a function value to a field it works OK
$_test = tNG_generateRandomString(16);

but when I try and use it in an update statement, it returns function not found.

UPDATE tblMembers2 SET tblMembers2.mSecKey= tNG_generateRandomString(16) WHERE tblMembers2.mID>0;

I've tried putting single, double quotes around the function without success

appreciate any help
Thanks
Clive

UPDATE tblMembers2 SET tblMembers2.mSecKey= tNG_generateRandomString(16) WHERE tblMembers2.mID>0
 
Hi

Maybe this ?
Code:
$sql="UPDATE tblMembers2 SET tblMembers2.mSecKey='" . [url=http://php.net/mysql_real_escape_string/]mysql_real_escape_string[/url](tNG_generateRandomString(16)) . "'WHERE tblMembers2.mID>0";

Feherke.
 
to the OP

the reason for your difficulty is that within double quotes references to procedural functions are not expanded or evaluated. they are taken as string literals. references to class methods, however, are expanded (and evaluated) within double quotes. thus to use a php function inside a sql string, you need, as feherke shows, to break out of the string and evaluate the function.

feherke separately points out the importance of escaping data used in sql queries.
 
Many Many Thanks for the advice

It was spot on!
I've meddling with this for a couple of days and would never havesolved it wiothout your help.

Best wishes Clive
 
as a sidebar to what i wrote above, you can use functions inside a string by overloading class methods. if that does not mean anything to you then stick with the basic fact that you can't use functions. it's better coding practice anyway, imo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top