Jump to content

Parse error in simple math script.


Alecdude

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/136356-parse-error-in-simple-math-script/
Share on other sites

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

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']}'";

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.

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>"); }
}

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>"); }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.