Jump to content

Insert into table if id matches session id


Shadowing

Recommended Posts

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.

Link to comment
Share on other sites

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'])."'")

Link to comment
Share on other sites

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.

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.