afinch;10906382 wrote:Hi,
$oq=$db->query("SELECT * FROM users WHERE userid={$POST['userid']}");
$rm=$db->fetch_row($oq);
$db->query("UPDATE users SET userpass='md5('{$POST['userpass']}') WHERE userid={$POST['userid']}");
stafflog_add("Edited password {$POST['username']} [{$_POST['userid']}]");
print "User edited....";
}
Can anyone shed any light on why this isnt working???
A quick example for you to build on would be something like this:
// sanitize and alias as bradgrafelman stated
$pass = md5($POST['userpass']);
$user = mysql_real_escape_string($POST['userid']);
// an example of typecasting as bradgrafelman once again stated
$value = (int)$value; // casts $value as an integer. You can do this with other datatypes as well such as (boolean)
$db->query("UPDATE users SET userpass='".$pass."' WHERE userid='".$user."'");
Those quotes are like so: ' " . $variable . " '
That's just a personal preference for syntax that I have - I find it makes reading the variables and colour coding easier.
Also, depending on the circumstances, a quick way to sanitize your data would be to do something like this(again something to build on):
foreach($POST as $k=>$v){
$POST[$k] = mysql_real_escape_string($_POST[$k]);
}
Hope this helps.