Click to See Complete Forum and Search --> : Update statement with $session...


Dieneces
02-26-2009, 06:52 AM
Hello guys,

I'm having trouble understanding how to update my table. Well... Im having trouble in using the where clause of update.

Is it possible to do something like this:

UPDATE player SET var1='10' where Nome=$_SESSION['Name']

I know that session can't be used that way.... but I would like to update the database in the user logged in row...

What is the best way to achive this? I'm now trying to understand the session_ID and stuff like that...


Many thanks in advance,

bogocles
02-26-2009, 08:27 AM
$query = "UPDATE `player` SET `var1` = '10' WHERE `Nome` = '{$_SESSION [ 'Name' ]}'";


That is MySQL. Drop those accent marks if you're not using that DB. Also, 'Nome' might be 'Name'?

Dieneces
02-26-2009, 09:03 AM
$q = "UPDATE player SET EXP = 10 WHERE Nome = {$_SESSION["Nome"]}";


This way it works. But:


Unknown column 'Dieneces' in 'where clause'


Ok... I dont understand this... The column is "Nome".... the "Dieneces" is the name of the user in the session so it should work... Why is the {$_SESSION["Nome"]} beeing treated like a column?

bogocles
02-26-2009, 09:09 AM
You left off the apostrophes that are supposed to go around the $_SESSION variable. Without them, which is what you posted, SQL looks for a column. With them, SQL looks for a value. Go back and look carefully at the example I posted. You need those apostrophes. :)

Dieneces
02-26-2009, 09:14 AM
Ok, this way it "works":

$q = "UPDATE player SET EXP = 10 WHERE Nome = '{$_SESSION['Nome']}'";

The problem is that it wont update the value... and even more strange is that it doesn't send back an error with the debug:

echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>';

Dieneces
02-26-2009, 09:25 AM
Forget it... this one was even more lamme... I wanted to increment +10 #) and I was changing the value to 10...

Many many thanks for the quick reply bogocles :)