scooby1 Posted February 8, 2012 Share Posted February 8, 2012 Hello I was wondering if anyone can spot what I am doing wrong here been trying to get it to work for a good few hours now with no luck! Basically.... A customer logs in = isadmin = 0. It then makes three session vairables: logged in vairable username vairable user id vairable This all works fine it's only when I try to add the second bit which is after the 3 vairables are created another select statement is done to check if there are any orders by this user in the order table. For example where the session "userid" = the customer id in the order table. If there is an order by this user another session vairable will be created carrying the order id if there are no orders the session vairable will not be set. All I seem to get is "warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result..." I hope this makes sense! Don't hesitate to ask if not! Thanks for taking your time having a look. $sqlu = mysql_query("SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword' AND isadmin='0'"); $sqla = mysql_query("SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword' AND isadmin='1'"); if(mysql_num_rows($sqlu)==1) { $resultu = mysql_fetch_assoc($sqlu); $_SESSION["loggedin"] = 1; $_SESSION["gatekeeper"] = $myusername; $_SESSION['userid'] = $resultu['ID']; $ordersql = "SELECT id FROM order WHERE customer_id = '".$_SESSION['userid']."' AND status < 2"; $orderresult = mysql_query($ordersql); $orderrow = mysql_fetch_assoc($orderresult); session_register("ordernum"); $_SESSION['ordernum'] = $orderrow['id']; header("location:menu.php"); } elseif(mysql_num_rows($sqla) == 1) { $resulta = mysql_fetch_assoc($sqla); $_SESSION['admin'] = $myusername; header("location:admincentre.php"); } else header("location:tryagain.php"); ?> Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted February 8, 2012 Share Posted February 8, 2012 you are using session_start at the top of your page, correct? Quote Link to comment Share on other sites More sharing options...
scooby1 Posted February 8, 2012 Author Share Posted February 8, 2012 Yes I have session start(); then I connect to my database. Would I be right in thinking that "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result" this error is kind of saying there is a problem with the select statement result? Maybe I've done the select statement wrong? Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted February 8, 2012 Share Posted February 8, 2012 "order" is a mysql reserved word in order to use this keyword in a query, it must be encased in back ticks: $ordersql = "SELECT id FROM `order` WHERE customer_id = '".$_SESSION['userid']."' AND status < 2"; Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 8, 2012 Share Posted February 8, 2012 Echo your query and the output from mysql_error. EDIT: Actually, don't bother. ORDER is a MySQL reserved word. http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html Quote Link to comment Share on other sites More sharing options...
scooby1 Posted February 8, 2012 Author Share Posted February 8, 2012 Wow you guys are awesome! Why didn't I come on here earlier! Ha! Thanks. Quote Link to comment 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.