sam06 Posted July 10, 2008 Share Posted July 10, 2008 I haven't a clue why this is doing this: My code: <?php $id = $_GET['id']; $username = $_GET['user']; mysql_connect("*************") or die(mysql_error()); mysql_select_db("****************") or die(mysql_error()); //gets sweet points $check = mysql_query("SELECT points FROM sweetshop WHERE id='$id'") or die(mysql_error()); $sweetpoints = mysql_result ($check, 0, 'points'); // gets sweet name $check1 = mysql_query("SELECT name FROM sweetshop WHERE id='$id'") or die(mysql_error()); $sweetname = mysql_result ($check1, 0, 'name'); //gets points of user $check = mysql_query("SELECT totalpoints FROM usertable WHERE username='$username'") or die(mysql_error()); $userpoints = mysql_result ($check, 0, 'totalpoints'); //works out new point total $difference = $userpoints - $sweetpoints; if ( $userpoints >= $sweetpoints ) { mysql_query("INSERT INTO sweets (name, username) VALUES('$sweetname', '$username' ) ") or die(mysql_error()); mysql_query("UPDATE usertable SET totalpoints='$difference' WHERE username='$username'") or die(mysql_error()); echo '<p><font size="4" face="Arial">Thanks for adding a sweet.</font></p> <p><font size="4" face="Arial"><a href="javascript:history.go(-1)">Click here to go back.</a></font></p>'; } else { echo "Not enough points"; echo '<p><font size="4" face="Arial"><a href="javascript:history.go(-1)">Click here to go back.</a></font></p>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/114127-solved-unexpected-t_variable-on-line-1/ Share on other sites More sharing options...
rhodesa Posted July 10, 2008 Share Posted July 10, 2008 you probably have some 'hidden' character at the beginning...put open a new plain text file, and copy paste the code into it. then save the new file over the old one. Quote Link to comment https://forums.phpfreaks.com/topic/114127-solved-unexpected-t_variable-on-line-1/#findComment-586621 Share on other sites More sharing options...
wildteen88 Posted July 10, 2008 Share Posted July 10, 2008 I cannot see anything wrong with that code. However this is bad programming practice: $check = mysql_query("SELECT points FROM sweetshop WHERE id='$id'") or die(mysql_error()); $sweetpoints = mysql_result ($check, 0, 'points'); // gets sweet name $check1 = mysql_query("SELECT name FROM sweetshop WHERE id='$id'") or die(mysql_error()); $sweetname = mysql_result ($check1, 0, 'name'); //gets points of user $check = mysql_query("SELECT totalpoints FROM usertable WHERE username='$username'") or die(mysql_error()); $userpoints = mysql_result ($check, 0, 'totalpoints'); You are running 3 queries to return the points, name and totalpoints from the sweetshop and usertable tables. MySQL can return multiple columns (which are in different tables) from a single SQL query. Quote Link to comment https://forums.phpfreaks.com/topic/114127-solved-unexpected-t_variable-on-line-1/#findComment-586625 Share on other sites More sharing options...
sam06 Posted July 10, 2008 Author Share Posted July 10, 2008 That was weird, but it certainly worked Cheers Quote Link to comment https://forums.phpfreaks.com/topic/114127-solved-unexpected-t_variable-on-line-1/#findComment-586826 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.