Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am getting a php with my mysql query that I'm trying to execute, and for the life of me I can't figure it out. I have tried wrapping the variable $money_earned in single quotes to no avail. It is a float. The $userdata variable is a string. I get this error when I run my code:

Parse error: syntax error, unexpected T_STRING

Here is my mysql query:

$query = "UPDATE `authentication` SET `money` = money + $money_earned WHERE `username` = '$userdata'";
mysql_query($query);

Here I will post the full code, hopefully that will allow this to be solved easier:

<?php

mysql_connect("blahblahblah");
mysql_select_db(blah) or die("Unable to select database");

$userdata = $_SESSION['userz'];
$secret_key = "TOPSECRET";
$user = $_GET['snuid'];
$money_earned = $_GET['currency'];
$id = $_GET['id'];
$secret = $_GET['verifier'];

$secret_check = md5($id.":".$user.":".$money_earned.":".$secret_key);

if($secret == $secret_check) {

   $query = "UPDATE `authentication` SET `money` = money + $money_earned WHERE `username` = '$userdata'";
   mysql_query($query);
 
} else {

}
share|improve this question
1  
I don't see any syntax errors. Are you sure that the error refers to these lines? –  Pavel Strakhov Nov 26 '12 at 19:38
    
I'm positive. That's why I don't understand... –  Twisterz Nov 26 '12 at 19:40
1  
Please include more of the code. This error usually shows up after a missing quote. –  G-Nugget Nov 26 '12 at 19:42
1  
Did you cut and past any of those lines? you may have a "special" quote in the actual code. –  Michael Harroun Nov 26 '12 at 19:42
1  
there's nothing visibly wrong with it. paste it in notepad, copy that, paste it back. –  Popnoodles Nov 26 '12 at 19:54

2 Answers 2

Few things I noticed, although not related to the parse error you're receiving (as other's have noted, your code appears to be correct syntax wise).

  1. You do not session_start(); before you call the $_SESSION['userz']; variable.
  2. You should escape your $userdata with the following: $userdata = mysql_real_escape_string($_SESSION['userz']);
  3. Think about switching to PDO for mysql.
share|improve this answer
    
Thank you for this. I upvoted you, but I don't think I can really accept your answer as it wasn't technically the answer to my question. –  Twisterz Nov 26 '12 at 20:00
    
I Understand and appreciate the upvote. Keep us informed as to what you find to be the cause of the parse error. –  jmgardn2 Nov 26 '12 at 20:01
    
As popnoodles suggested in the comments I copied it into notepad and then copied it back and it seemed to work. I'm completely blown away as to why it initially gave me a parse error... –  Twisterz Nov 26 '12 at 20:03

Try to concatenate the string like:

$query = "UPDATE authentication SET money = money + ". $money_earned." WHERE username = ".$userdata; mysql_query($query);

share|improve this answer
1  
the error is PHP not SQL –  Popnoodles Nov 26 '12 at 19:46
    
That would cause a new problem since $userdata isn't quoted. –  G-Nugget Nov 26 '12 at 19:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.