Jump to content

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

$_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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.