neex1233 Posted June 18, 2009 Share Posted June 18, 2009 I'm getting the error that's in the subject. Here is my code: <?php require 'config.php'; $id = $_SESSION['id']; $sql = "UPDATE users SET tokens=(tokens+$t) WHERE id=$id" srand ((double) microtime( )*1000000); $t = rand(2,75); mysql_query($sql); echo "You won $t tokens!"; ?> The error is not in config.php Thanks! EDITED BY akitchin: please use code tags in future posts here. Quote Link to comment https://forums.phpfreaks.com/topic/162820-parse-error-syntax-error-unexpected-t_string-help/ Share on other sites More sharing options...
Maq Posted June 18, 2009 Share Posted June 18, 2009 Missing ';' after $id" Quote Link to comment https://forums.phpfreaks.com/topic/162820-parse-error-syntax-error-unexpected-t_string-help/#findComment-859193 Share on other sites More sharing options...
ldougherty Posted June 18, 2009 Share Posted June 18, 2009 change $sql = "UPDATE users SET tokens=(tokens+$t) WHERE id=$id" to mysql_query("UPDATE users SET tokens=(tokens+$t) WHERE id=$id"); Quote Link to comment https://forums.phpfreaks.com/topic/162820-parse-error-syntax-error-unexpected-t_string-help/#findComment-859198 Share on other sites More sharing options...
Maq Posted June 18, 2009 Share Posted June 18, 2009 change $sql = "UPDATE users SET tokens=(tokens+$t) WHERE id=$id" to mysql_query("UPDATE users SET tokens=(tokens+$t) WHERE id=$id"); I like putting the query in a string first, that way you can echo it out and see what it actually contains, and it's easier to manipulate. Quote Link to comment https://forums.phpfreaks.com/topic/162820-parse-error-syntax-error-unexpected-t_string-help/#findComment-859203 Share on other sites More sharing options...
neex1233 Posted June 18, 2009 Author Share Posted June 18, 2009 This is my new code: <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); require 'config.php'; $username = $_SESSION['username']; $t = rand(2,75); $sql = "UPDATE users SET tokens=(tokens+$t) WHERE username=$username"; srand ((double) microtime( )*1000000); mysql_query($sql); echo "You won $t tokens!"; ?> It doesn't work, but I don't get an error. Quote Link to comment https://forums.phpfreaks.com/topic/162820-parse-error-syntax-error-unexpected-t_string-help/#findComment-859219 Share on other sites More sharing options...
Maq Posted June 18, 2009 Share Posted June 18, 2009 Put single quotes around $username: WHERE username='$username'"; Quote Link to comment https://forums.phpfreaks.com/topic/162820-parse-error-syntax-error-unexpected-t_string-help/#findComment-859222 Share on other sites More sharing options...
neex1233 Posted June 18, 2009 Author Share Posted June 18, 2009 Thanks, it works now!! Quote Link to comment https://forums.phpfreaks.com/topic/162820-parse-error-syntax-error-unexpected-t_string-help/#findComment-859223 Share on other sites More sharing options...
Maq Posted June 18, 2009 Share Posted June 18, 2009 Thanks, it works now!! Good. The only type you don't have to put single quotes around are integers. Quote Link to comment https://forums.phpfreaks.com/topic/162820-parse-error-syntax-error-unexpected-t_string-help/#findComment-859226 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.