yogibear Posted May 15, 2007 Share Posted May 15, 2007 Hi all I am quite new to php and am having a little problem with sessions. when a user logs in there username becomes a session and every page checks this session this all works fine, which is great but I would like it to search the database for this username this is part of the code that i have. mysql_query("UPDATE userinformation SET credits = $c WHERE username = ". $_SESSION['username']; mysql_close($con); this is the error I am getting Parse error: syntax error, unexpected ';' in sorry if i have not been clear, I hope you can help, thanks in advanced yogi Quote Link to comment https://forums.phpfreaks.com/topic/51554-solved-session-mysql/ Share on other sites More sharing options...
pikemsu28 Posted May 15, 2007 Share Posted May 15, 2007 just glancing over your code you didnt close the parenthesis. mysql_query("UPDATE userinformation SET credits = $c WHERE username = ". $_SESSION['username']); mysql_close($con); Quote Link to comment https://forums.phpfreaks.com/topic/51554-solved-session-mysql/#findComment-253895 Share on other sites More sharing options...
yogibear Posted May 16, 2007 Author Share Posted May 16, 2007 Hi thanks for your fast reply, I thought everything was working when I got no error but then I noticed that it has stopped the calculation from working. This is all my work in progress code <? // You may copy this PHP section to the top of file which needs to access after login. session_start(); // Use session variable on this page. This function must put on the top of page. if(!session_is_registered("username")){ // if session variable "username" does not exist. header("location:index.php"); // Re-direct to index.php } $con = mysql_connect('localhost','***','***'); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("***", $con); $result = mysql_query("SELECT * FROM userinformation WHERE username='yogibear'"); while($row = mysql_fetch_array($result)) $a = $row['credits']; $b = 5000; $c = $a + $b; mysql_query("UPDATE userinformation SET credits = $c WHERE username = ". $_SESSION['username']"); mysql_close($con); ?> [code] The code is meant to take credits and add 5000 to it and then replace the original amount of credits with the total, but it doesn’t, it does when ". $_SESSION['username']"); is replaced with 'yogibear'"); Any ideas Thanks [/code] Quote Link to comment https://forums.phpfreaks.com/topic/51554-solved-session-mysql/#findComment-254423 Share on other sites More sharing options...
pikemsu28 Posted May 16, 2007 Share Posted May 16, 2007 if this is your exact code you are missing a period after the $_session variable mysql_query("UPDATE userinformation SET credits = $c WHERE username = '". $_SESSION['username']."'); you have ".$_SESSION['username']") if that doesn't work, make sure you have your sessions set. EDIT: Also you need single quotes around the session variable before the double quotes. Quote Link to comment https://forums.phpfreaks.com/topic/51554-solved-session-mysql/#findComment-254453 Share on other sites More sharing options...
yogibear Posted May 16, 2007 Author Share Posted May 16, 2007 Hi now im getting an error Parse error: syntax error, unexpected $end in /home/sites/bf2c.co.uk/public_html/orderexhaust.php on line 27 This is all the code <? // You may copy this PHP section to the top of file which needs to access after login. session_start(); // Use session variable on this page. This function must put on the top of page. if(!session_is_registered("username")){ // if session variable "username" does not exist. header("location:index.php"); // Re-direct to index.php } $con = mysql_connect('localhost','***','***'); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("***", $con); $result = mysql_query("SELECT * FROM userinformation WHERE username='yogibear'"); while($row = mysql_fetch_array($result)) $a = $row['credits']; $b = 5000; $c = $a + $b; mysql_query("UPDATE userinformation SET credits = $c WHERE username = '". $_SESSION['username']."'); mysql_close($con); ?> Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/51554-solved-session-mysql/#findComment-254520 Share on other sites More sharing options...
pikemsu28 Posted May 16, 2007 Share Posted May 16, 2007 we both left off a double quote at the end of the query before the closing parenthesis....sorry for that one. mysql_query("UPDATE userinformation SET credits = $c WHERE username = '". $_SESSION['username']."'"); Quote Link to comment https://forums.phpfreaks.com/topic/51554-solved-session-mysql/#findComment-254606 Share on other sites More sharing options...
yogibear Posted May 16, 2007 Author Share Posted May 16, 2007 works great thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/51554-solved-session-mysql/#findComment-254725 Share on other sites More sharing options...
pikemsu28 Posted May 16, 2007 Share Posted May 16, 2007 no problem, anytime! Quote Link to comment https://forums.phpfreaks.com/topic/51554-solved-session-mysql/#findComment-254748 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.