Jump to content

Recommended Posts

Hi,

 

I am working on a account page for my site, and am stuck with the SQL query.  I use the foreach function so that fields don't get erased with blank info.  But now my problem is sanitizing the information.  Here is my code so far:

 

$qry = 'UPDATE user SET ';

foreach($edituser as $key => $value)
{

if(!empty($value))
{

$qry .= $key . '="' . $value . '", ';

}

}

$qry = substr($sql, 0, -2); //Remove the last space and ,

$qry .= ' WHERE userid=' . $userid;

 

Which works fine, but the posted data is not sanitized.  The only way I can think of sanitizing it is running it all thru a filter like this:

 

$value = preg_replace("/[^A-Za-z0-9]/", "", $value);

 

Which seems simple enough, but I can't do it this way for all fields.  I also can't figure out how to encrypt the new posted password... What would be the simplest way to go about filtering/encrypting data when using the "foreach" function?

 

Thanks!

You could simply addslashes() the data, no?

 

And are you trying to encrypt every field cause that would be easy.... If you're only trying to encrypt the password though, you have no way of knowing which value is which ;p....  Well you could keep up with an incremented variable, but from the look of the foreach, you're receiving a different number of variables some times....

Hi Thorpe, Corbin. Thanks for the tip, I will be using mysql_escape_real_string.  I also found a very handy function for using it posted by wildteen88 here:

 

http://www.phpfreaks.com/forums/index.php/topic,130495.msg547518.html#msg547518

 

Thanks!

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.