Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I put a seesion variable in sql query?

Status
Not open for further replies.

pugs421

Technical User
Joined
Nov 25, 2002
Messages
114
Location
US
I cant figure out the right way to put the session varible into the query. (quotes, parenthesis, etc).



"INSERT INTO setup (photo) VALUES ('$f_org') WHERE screen_name = $_SESSION['screen_name']",

Any ideas?
 
[tt]$query = "INSERT INTO setup (photo) VALUES ('$f_org') WHERE screen_name = '" . $_SESSION['screen_name'] . "'";[/tt]
should do it.

//Daniel
 
I'm getting this error message when trying to insert the data using '" . $_SESSION['screen_name'] . "'";

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE screen_name = 'test_screenname'' at line 1.

test_screenname being the value of the session variable. Any ideas of what I'm doing wrong?
 
I'm must be doing something wrong because I'm sure the syntax you gave me is correct. I'll figure it out. Thanks.
 
I just read through the query. You can't do an [tt]INSERT[/tt] with a [tt]WHERE[/tt] clause.

//Daniel
 
:o lmao. I'm trying to add information to a row that already has information in it. INSERT WHERE made sence to me. Back to the books.

________

newb
 
Then you should use an [tt]UPDATE[/tt] query, something like
[tt]$query = "UPDATE setup SET photo = '$f_org' WHERE screen_name = '" . $_SESSION['screen_name'] . "'";[/tt]
should work if I understand correctly.

//Daniel
 
Thanks a bunch. I cant believe how much time I wasted on something so stupid. thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top