Shadowing Posted December 9, 2011 Share Posted December 9, 2011 Im trying to insert a name into my database but I need it to go into the column that matches the sessions user id "INSERT INTO users SET name = '".$_POST['name']."'"; how do I tell it to put name into name column with id matching Session id. really appreicate if someone could please help me with this. Quote Link to comment Share on other sites More sharing options...
xyph Posted December 9, 2011 Share Posted December 9, 2011 UPDATE `users` SET `name` = '$name' WHERE `id` = '$id' Don't forget to sanitize your user-supplied data. Quote Link to comment Share on other sites More sharing options...
Shadowing Posted December 9, 2011 Author Share Posted December 9, 2011 thanks for the reply xyph huge help do I need to sanitize it twice like this? $sql = "UPDATE 'users' SET 'goauld' = '".mysql_real_escape_string($_POST['goauld'])."' WHERE 'id' = '".mysql_real_escape_string($_SESSION['user_id'])."'"; how do I seperate this code so its on seperate lines? also is there a reason why this code below doesnt use ' ' around users $results = mysql_query("UPDATE users SET userip='".mysql_real_escape_string($_SERVER['REMOTE_ADDR'])."',login_ip='".mysql_real_escape_string($roe['login_ip'])."' WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'") Quote Link to comment Share on other sites More sharing options...
Shadowing Posted December 9, 2011 Author Share Posted December 9, 2011 I must have something wrong its giving me a error Edit: nevermind i fixed the error Quote Link to comment Share on other sites More sharing options...
xyph Posted December 9, 2011 Share Posted December 9, 2011 It really depends. Was $_SESSION['id'] populated from user-data, or from a previous MySQL query? Only user-data needs to be sanitized. - how do I seperate this code so its on seperate lines? Use the {Enter} key on your keyboard. - also is there a reason why this code below doesnt use ' ' around users users is a table name, thus should not be quoted. It's basic MySQL syntax. Quote Link to comment Share on other sites More sharing options...
Shadowing Posted December 10, 2011 Author Share Posted December 10, 2011 thanks alot for the help xyph Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.