karlclef Posted June 15, 2015 Share Posted June 15, 2015 Please, when i run the below php code it shows the following errors: Notice: Undefined index: uid in C: Notice: Undefined index: upass in C: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C: HERE is the code: if (!isset($_POST['role']) or $_POST['role'] == 'user') { if (isset($_POST['logout']) && $_POST['logout'] == 'yes') { session_start(); session_end(); set_session_cookie('uname', ''); exit; } $user = mysql_fetch_assoc(mysql_queryf("select Cust_Name, Cust_ID from Customer where Cust_ID = %s and Passwd = %s", $_POST['uid'], $_POST['upass'])); if ($user) { session_start(); $_SESSION['uid'] = $user['Cust_ID']; set_session_cookie('uname', $user['Cust_Name']); } } elseif ($_POST['role'] == 'rest') { if (isset($_POST['logout']) && $_POST['logout'] == 'yes') { session_start(); session_end(); set_session_cookie('rname', ''); exit; } $user = mysql_fetch_assoc(mysql_queryf("select Rest_Name, Rest_ID from Restaurant where Rest_ID = %s and Passwd = %s", $_POST['rid'], $_POST['rpass'])); if ($user) { session_start(); $_SESSION['rid'] = $user['Rest_ID']; set_session_cookie('rname', $user['Rest_Name']); } } else exit; ?> Any Help to fix it? Link to comment Share on other sites More sharing options...
justsomeguy Posted June 15, 2015 Share Posted June 15, 2015 It means that $_POST['uid'] and $_POST['upass'] are not set. You can use the isset function to check if something is set before trying to use it. Link to comment Share on other sites More sharing options...
dauruk0512 Posted June 16, 2015 Share Posted June 16, 2015 yes like user said aboeve but this is another way for me <?php <!---add this script in your above ---> error_reporting ('0'); if (!isset($_POST['role']) or $_POST['role'] == 'user') { if (isset($_POST['logout']) && $_POST['logout'] == 'yes') { session_start(); session_end(); set_session_cookie('uname', ''); exit; } $user = mysql_fetch_assoc(mysql_queryf("select Cust_Name, Cust_ID from Customer where Cust_ID = %s and Passwd = %s", $_POST['uid'], $_POST['upass'])); if ($user) { session_start(); $_SESSION['uid'] = $user['Cust_ID']; set_session_cookie('uname', $user['Cust_Name']); } } elseif ($_POST['role'] == 'rest') { if (isset($_POST['logout']) && $_POST['logout'] == 'yes') { session_start(); session_end(); set_session_cookie('rname', ''); exit; } $user = mysql_fetch_assoc(mysql_queryf("select Rest_Name, Rest_ID from Restaurant where Rest_ID = %s and Passwd = %s", $_POST['rid'], $_POST['rpass'])); if ($user) { session_start(); $_SESSION['rid'] = $user['Rest_ID']; set_session_cookie('rname', $user['Rest_Name']); } } else exit; ?> Link to comment Share on other sites More sharing options...
karlclef Posted June 16, 2015 Author Share Posted June 16, 2015 Thanks a lot, i have been able to fix the problem by the help of your kind suggestions.This really helped. Link to comment Share on other sites More sharing options...
dauruk0512 Posted June 17, 2015 Share Posted June 17, 2015 who's script working ! me or user above Link to comment Share on other sites More sharing options...
karlclef Posted June 17, 2015 Author Share Posted June 17, 2015 User above Link to comment Share on other sites More sharing options...
karlclef Posted June 17, 2015 Author Share Posted June 17, 2015 dauruk0512 , i just tried your code, yours is also working.Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now