Page 1 of 1

updating a row using the session variables

Posted: Mon Jun 30, 2003 4:29 pm
by Red Midnight
--MySQL questions---

<?php
session_start();

$user=$_SESSION['user'];
$pass=$_SESSION['pass'];

$query="UPDATE users SET name=". $_SESSION['user'] .", password=". $_SESSION['pass'] .", strength=". $_SESSION['strength'] .", defense=". $_SESSION['defense'] .", powerlevel=". $_SESSION['powerlevel'] .", int=". $_SESSION['int'] .", hp=". $_SESSION['hp'] .", job=". $_SESSION['job'] .", gold=". $_SESSION['gold'] ." WHERE name=$user AND password=$pass";

$result=mysql_query($query) or die("Error in query:".mysql_error());

?>

I don't understand why this isnt working. It's giving me this---

Error in query:You have an error in your SQL syntax near 'int=1, hp=10, job=none, gold=40 WHERE name=Gohan AND password=e5e65fce9273c4762a' at line 1

can anyone please tell me what I typed wrong here? I've been sitting here forever to find out what I did wrong.

Posted: Mon Jun 30, 2003 6:43 pm
by SBukoski
What are all the variables getting set to in your UPDATE statement? Is it possible that one of them contains a comma and is throwing things off? I generally put single quotes around all my variables when I do this. For example:

Code: Select all

$query="UPDATE users SET name='$_SESSION[user]', password='$_SESSION[pass]', strength='$_SESSION[strength]', defense='$_SESSION[defense]', powerlevel='$_SESSION[powerlevel]', int='$_SESSION[int]', hp='$_SESSION[hp]', job='$_SESSION[job]', gold='$_SESSION[gold]' WHERE name='$user' AND password='$pass'";

Posted: Mon Jun 30, 2003 9:29 pm
by Red Midnight
I put in what you said and I get this:

Error in query:You have an error in your SQL syntax near 'int='1', hp='10', job='none', gold='40' WHERE name='Gohan' AND password='e5e65fc' at line 1

this thing is annoying

Posted: Mon Jun 30, 2003 10:23 pm
by SBukoski
AH!! I think it just dawned on me. INT is a reserved word in MySQL to define a datatype. So it is getting confused when you are trying to use it in this SQL statement. Try changing the column name to something different and see if it works.

Posted: Tue Jul 01, 2003 3:12 am
by twigletmac
This is a handy bookmark to use when designing tables (can prevent many headaches):
http://www.mysql.com/doc/en/Reserved_words.html

Mac

Posted: Fri Jul 04, 2003 6:38 pm
by bionicdonkey
you will need quotes around the values who's db field is varchar and other text related ones