Jump to content

PHP script showing undifined index error


karlclef

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...