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),
));

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.