Jump to content

format for this string?


desjardins2010

Recommended Posts

I like sprintf and vsprintf for this -- more separation. Just another option in a sea of many.

 

$q = "UPDATE members SET logfile = '%s admin logged into long2ip(%s)' WHERE username='%s'";
$q = vsprintf($q, array(
mysql_real_escape_string($playerlog),
$ip,
mysql_real_escape_string($player),
));

FYI, the issue here is that you are putting a php method (and variable) inside single quotes ('...').  PHP does not parse syntax/variables in single quotes, it treats it as plain text.  You can get php to parse a variable inside quotes if you use double quotes ("..."), but it won't parse the php function, so you have to break out of the quotes and concatenate as BlueSkyIS has shown. 

 

@bibby: your solution won't work because long2ip() is a php function. You will have to move long2ip() to wrap around $ip and just use %s in the query string.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.