Jump to content

Help in building a PHP MYSQL insert statement.


wmarcy

Recommended Posts

My MYSQL - mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $

 

Here is a code snippet, as you can see I am novice, but working my way through the books. 

 

The query needs to insert into a table (current_xeep) the user_id from the $_SESSION variable and the user_name from the $_SESSION variable.  the $_SESSION variables are set and they do contain the correct information.  I am having trouble in building the insert statement. 

 

$query = "(INSERT INTO current_xeep (id, user_id, user_name) VALUES ('', '$_SESSION["user_id"]', '$_SESSION["user_name"]')";

 

Thanks for any help!

Link to comment
Share on other sites

Well, in hopes that someone might stumble on this and be in dire need for the answer, this is how I solved it:

 

$hold1 = $_SESSION["user_id"];

$hold2 = $_SESSION["user_name"];

 

$query = "INSERT INTO current_xeep (id, user_id, user_name) VALUES ('', '$hold1', '$hold2')";

 

Not elegant at all, but it works. 

Link to comment
Share on other sites

Leave out the id and '' parts.

 

The second way you did it is fine, and looks nice. You could also use concatenation but it's a bit harder to read.

$query = "INSERT INTO current_xeep (user_id, user_name) VALUES ('".$_SESSION['user_id']."', '".$_SESSION['user_name']."'";

There's a way to use {} but I find it even harder to read.

 

 

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.