[SOLVED]Help with Notice: Undefined index:

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
bironeb
Forum Commoner
Posts: 59
Joined: Thu Nov 20, 2003 12:02 pm

[SOLVED]Help with Notice: Undefined index:

Post by bironeb »

My code for the php front end of my MySql database is giving an error. Below is my php code:

Code: Select all

<?//start a session
session_start();
$msg = "";
$valid = "";
//check if user is coming from a form
if ($_POST['op'] == "ds") {

	//check username and password
	if (($_POST[username] != "admin") || ($_POST[password] != "abc123")) {

		//handle bad login
		$msg = "<P><font color="#FF0000 "><strong>Bad Login - Try Again</strong></font></P>";
		$show_form = "yes";
	
	} else {

		//handle good login
		$valid = "yes";
		$_SESSION[valid] = $valid;
		$show_menu = "yes";
	}

} else {

	//determine what to show
	if ($valid == "yes") {
		$show_menu = "yes";
	} else {
		$show_form = "yes";
	}
}

//build form block
$form_block ="
<h1>Login</h1>
<form method=POST action="$_SERVER[PHP_SELF]">

$msg

<P><strong>username:</strong><br>
<input type="text" name="username" size=15 maxlength=25></P>

<P><strong>password:</strong><br>
<input type="password" name="password" size=15 maxlength=25></P>

<input type="hidden" name="op" value="ds">

<P><input type="submit" name="submit" value="login"></P>
</FORM>";

//build menu block
$menu_block ="
<h1>My Contact Administration System</h1>
<P><strong>Administration</strong>
<ul>
<li><a href="show_addcontact.php">Add a Contact</a>
<li><a href="pick_modcontact.php">Modify a Contact</a>
<li><a href="pick_delcontact.php">Delete a Contact</a>
</ul>
<P><strong>View Records</strong>
<ul>
<li><a href="show_contactsbyname.php">Show Contacts, Ordered by Name</a>
</ul>";

//assign the block to show to the $display_block variable
if ($show_form == "yes") {
	$display_block = $form_block;
} else if ($show_menu == "yes"){
	$display_block = $menu_block;
}

?>
<HTML>
<HEAD>
<TITLE>My Contact Management System</TITLE>
</HEAD>
<BODY>

<? echo "$display_block"; ?>

</BODY>
</HTML>
This is the Error im getting :

Notice: Undefined index: op on line 7

Line 7 is:

Code: Select all

if ($_POST['op'] == "ds") {
I know its got to be a simple solution, but i've not found an answer from my sources. Any ideas?
Last edited by bironeb on Wed Mar 24, 2004 6:35 pm, edited 1 time in total.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

if (!empty($_POST['op']) && $_POST['op'] == 'ds') {
User avatar
bironeb
Forum Commoner
Posts: 59
Joined: Thu Nov 20, 2003 12:02 pm

Post by bironeb »

Thanks markl999 you rock! I can always count on you. That worked great.
Post Reply