Jump to content

Login help


scooby1

Recommended Posts

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");
?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.