I have been trying to develop a script which adds 25 points into the users account if they manage to complete a challenge. I have no clue on how my script below doesn't work. It is just a little part from what I have got but it should be enough to explain the situation:
if (mysql_num_rows($result))
{
$row = mysql_fetch_assoc($result);
$points = $row['points'] + 25;
mysql_query("INSERT INTO members (points) VALUES ('$points') WHERE username = '".$_SESSION['username']."'");
echo "<center><h3><b>Well Done ".$_SESSION['username']."</b><h3>Application 1 Complete</center>";
mysql_close($link);
ooooh! ya LOL... the problem is points + 25, you can't do that in an SQL statment like that. First get teh points back and then add 25 to them then update the db....
Nah that don't work neither. Here is the actual code. Its very messy I know but it will be cleaned up soon.
if (strlen($app1) <> 0)
{
if ($app1 != "eclipse")
{
echo "Sorry, you have entered the wrong password!";
echo "<p>";
}
else
{
if ($app1 == "eclipse")
{
$link = mysql_connect("???", "???", "???");
mysql_select_db("connex") or die("Could not 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);
$points_up = $row['points'] + 25;
mysql_query("INSERT INTO members points = $points_up WHERE SesID = '$_SESSION['username']'") or die("Could not connect!");
echo "<center><h3><b>Well Done ".$_SESSION['username']."</b><h3>Application 1 Complete</center>";
mysql_close($link);
}
}
}
Yeah ok I got that one. Just a silly mistake. The only prob now is that the points are not even adding. I am using an INT variable for the points column. Mabey thats the probem???