Alecdude Posted December 10, 2008 Share Posted December 10, 2008 So, I messed around with my script for money, and it STILL DOESN'T WORK. Nothing ever works when Alec is behind it. NEVAR. So, here's the code: if ($_POST['Submit']=='Buy'){ if ($_SESSION['Money'] > 14){ $sql = "UPDATE users SET ".$_SESSION['Money']."=".$_SESSION['Money']."-15"; $sql2 = "UPDATE users SET ".$_SESSION['badge1']."=1" $result = mysql_query($sql) or die (mysql_error()); $result2 = mysql_query($sql2) or die (mysql_error()); echo "<h3>You have received your badge!</h3><br><a href=myaccount.php>Click here to go to your account</a>"; } else { die ("<h3>You either own this badge or do not have enough ARO$.</h3><br><p>Please click the back button to go back a page.</p>"); } } And the error is: Parse error: parse error, unexpected T_VARIABLE in /home/content/a/l/e/alecdude/html/login/badge1.php on line 14 Which is this line: $sql = "UPDATE users SET ".$_SESSION['Money']."=".$_SESSION['Money']."-15"; Please help, -Alec Quote Link to comment https://forums.phpfreaks.com/topic/136356-parse-error-in-simple-math-script/ Share on other sites More sharing options...
trq Posted December 10, 2008 Share Posted December 10, 2008 This line.... $sql2 = "UPDATE users SET ".$_SESSION['badge1']."=1" is missing a closing ; Quote Link to comment https://forums.phpfreaks.com/topic/136356-parse-error-in-simple-math-script/#findComment-711381 Share on other sites More sharing options...
Alecdude Posted December 10, 2008 Author Share Posted December 10, 2008 This line.... $sql2 = "UPDATE users SET ".$_SESSION['badge1']."=1" is missing a closing ; I fixed that, and am now getting this: 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 '15=15-15' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/136356-parse-error-in-simple-math-script/#findComment-711382 Share on other sites More sharing options...
trq Posted December 10, 2008 Share Posted December 10, 2008 $_SESSION['Money'] doesn't appear to hold a field name. Quote Link to comment https://forums.phpfreaks.com/topic/136356-parse-error-in-simple-math-script/#findComment-711384 Share on other sites More sharing options...
Alecdude Posted December 10, 2008 Author Share Posted December 10, 2008 $_SESSION['Money'] doesn't appear to hold a field name. I was thinking the same thing, as it accesses the user that is logged in's value. I don't know how to get access to a specific user's value using the field, so I guess I need help on that. Quote Link to comment https://forums.phpfreaks.com/topic/136356-parse-error-in-simple-math-script/#findComment-711389 Share on other sites More sharing options...
trq Posted December 10, 2008 Share Posted December 10, 2008 Ah, you your want to update a users 'Money' field? Providing you have some way of identifying the user stored within there $_SESSION array you can use that within a 'WHERE' clause. eg; $sql = "UPDATE users SET Money=Money-15 WHERE userid = '{$_SESSION['userid']}'"; Quote Link to comment https://forums.phpfreaks.com/topic/136356-parse-error-in-simple-math-script/#findComment-711394 Share on other sites More sharing options...
Alecdude Posted December 10, 2008 Author Share Posted December 10, 2008 Ah, you your want to update a users 'Money' field? Providing you have some way of identifying the user stored within there $_SESSION array you can use that within a 'WHERE' clause. eg; $sql = "UPDATE users SET Money=Money-15 WHERE userid = '{$_SESSION['userid']}'"; I changed that to fit the correct means for my site, and now I get this error: Query was empty I'm only half-sure about what this means. Please help. Quote Link to comment https://forums.phpfreaks.com/topic/136356-parse-error-in-simple-math-script/#findComment-711621 Share on other sites More sharing options...
trq Posted December 10, 2008 Share Posted December 10, 2008 Post your code. Quote Link to comment https://forums.phpfreaks.com/topic/136356-parse-error-in-simple-math-script/#findComment-711622 Share on other sites More sharing options...
Alecdude Posted December 10, 2008 Author Share Posted December 10, 2008 if ($_POST['Submit']=='Buy'){ if ($_SESSION['Money'] > 14){ $sql = "UPDATE users SET Money=Money-15 WHERE id = '{$_SESSION['user_id']}'"; $sql = "UPDATE users SET badge1=1 WHERE id = '{$_SESSION['user_id']}'"; $result = mysql_query($sql) or die (mysql_error()); $result2 = mysql_query($sql2) or die (mysql_error()); echo "<h3>You have received your badge!</h3><br><a href=myaccount.php>Click here to go to your account</a>"; } else { die ("<h3>You either own this badge or do not have enough ARO$.</h3><br><p>Please click the back button to go back a page.</p>"); } } Quote Link to comment https://forums.phpfreaks.com/topic/136356-parse-error-in-simple-math-script/#findComment-711623 Share on other sites More sharing options...
gevans Posted December 10, 2008 Share Posted December 10, 2008 if ($_POST['Submit']=='Buy'){ if ($_SESSION['Money'] > 14){ $sql = "UPDATE users SET Money=Money-15 WHERE id = '{$_SESSION['user_id']}'"; $sql = "UPDATE users SET badge1=1 WHERE id = '{$_SESSION['user_id']}'"; $result = mysql_query($sql) or die (mysql_error()); $result2 = mysql_query($sql2) or die (mysql_error()); echo "<h3>You have received your badge!</h3><br><a href=myaccount.php>Click here to go to your account</a>"; } else { die ("<h3>You either own this badge or do not have enough ARO$.</h3><br><p>Please click the back button to go back a page.</p>"); } } Try changing it to this; (check over to see what i've changed ) if ($_POST['Submit']=='Buy'){ if ($_SESSION['Money'] > 14){ $sql = "UPDATE users SET Money=($_SESSION['Money']-15) WHERE id = '{$_SESSION['user_id']}'"; $sql2 = "UPDATE users SET badge1=1 WHERE id = '{$_SESSION['user_id']}'"; $result = mysql_query($sql) or die (mysql_error()); $result2 = mysql_query($sql2) or die (mysql_error()); echo "<h3>You have received your badge!</h3><br><a href=myaccount.php>Click here to go to your account</a>"; } else { die ("<h3>You either own this badge or do not have enough ARO$.</h3><br><p>Please click the back button to go back a page.</p>"); } } Quote Link to comment https://forums.phpfreaks.com/topic/136356-parse-error-in-simple-math-script/#findComment-711627 Share on other sites More sharing options...
gevans Posted December 10, 2008 Share Posted December 10, 2008 Also, (if this works) you can change your script to only use one query!! You can update multiple fields in one table with a single query Quote Link to comment https://forums.phpfreaks.com/topic/136356-parse-error-in-simple-math-script/#findComment-711628 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.