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!

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. 

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.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.