wmarcy Posted April 24, 2012 Share Posted April 24, 2012 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! Quote Link to comment Share on other sites More sharing options...
wmarcy Posted April 24, 2012 Author Share Posted April 24, 2012 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 24, 2012 Share Posted April 24, 2012 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. 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.