[SOLVED] $_SESSION Problem!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

[SOLVED] $_SESSION Problem!!!

Post by Joe »

Recently I have been trying to create a points system for my site where users can gain points to their account by completing challenges. I am trying to update their current score by using a SESSION which holds their username. When I try to add 25 points to the account I get an error. The code go's like:

if ($app1 == "pass")
$link = mysql_connect("???", "???", "???");
mysql_select_db("???") or die("couldnt connect" . mysql_error());
$sql = "SELECT points FROM members WHERE SesID = $_SESSION['username']";
$result = mysql_query($sql) or die(mysql_error());

if (mysql_num_rows($result))
{
$row = mysql_fetch_assoc($result);
mysql_query("INSERT INTO members ('points') VALUES(points + 25"));
mysql_close($link);
}

Can anyone please help me with this problem??

Regards



Joe 8)
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

this should work :

$sql = "SELECT points FROM members WHERE SesID = '".$_SESSION['username']."'";
$result = mysql_query($sql) or die(mysql_error());

$row = mysql_result($result);
$points = $row + 25;

mysql_query("INSERT INTO members (points) VALUES('".$points."')");

unless your points field was declared as a varchar field. basically, you just wasn't using the quotes correctly. i added a little more to it, but shoudl work...
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

marking this thread at solved.
Post Reply