I'm getting this error on my webpage:
Notice: Undefined index: op in H:\Projects\f05\f05g04\html\prototype\mailinglistf orm.php on line 41
I thought I already defined op when I say:
<input type=\"hidden\" name=\"op\" value=\"ds\">
however, im still getting this error.
any suggestions?
Here's the php code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>shopPhilly</title>
<link rel="stylesheet" type="text/css"
href="/include/mailinglistsheet.css">
<style type="text/css" media="all">@import "mailinglistsheet.css";</style>
<meta name="author" content="Lauren Pisciotta" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<body>
<div id="content">
<h2> Join Our Mailing List! </h2>
<?php
//set up a couple of functions
function doDB( ) {
global $conn;
//open the connection
$conn = mysql_connect("hawk.csc.villanova.edu", "group04f05", "philly") or die(mysql_error());
mysql_select_db("shopping",$conn) or die(mysql_error());
}
function emailChecker($email) {
global $conn, $check_result;
//check that email is not already in list
$check = "select id from subscribers where email = '$email' ";
$check_result = mysql_query($check, $conn) or die (mysql_error());
}
//determine if they need to see the form or not
//"ds" stands for do something
if ($_POST['op'] != "ds") {
//they do, so create form block
$display_block = "<form method=POST action=\"$_SERVER[PHP_SELF]\">
<p><strong>Your E-Mail Address:</strong><br>
<input type=text name=\"email\" size=40 maxlength=150>
<p><strong>Action:</strong><br>
<input type=radio name=\"action\" value=\"sub\" checked> subscribe
<input type=radio name=\"action\" value=\"unsub\"> unsubscribe
<input type=\"hidden\" name=\"op\" value=\"ds\">
<p><input type=submit name=\"submit\" value=\"Submit Form\"></p>
</form>";
} else if (($_POST['op'] == "ds") && ($_POST['action'] == "sub")) {
//trying to subscribe; validate email address
if ($_POST['email'] == " ") {
header("Location: mailinglistform.php");
exit;
}
//connect to database
doDB( );
//check that email is in list
emailChecker($_POST['email']);
//get number of results and do action
if (mysql_num_rows($check_result) < 1) {
//add record
$sql = "insert into subscribers values(' ', '$_POST[email]')";
$result = mysql_query ($sql, $conn) or die(mysql_error( ));
$display_block = "<pp>Thanks for signing up! </p>";
} else {
//print failure message
$display_block = "<p>You're already subscribed! </p>";
}
} else if (($_POST['op'] == "ds") && ($_POST['action'] == "unsub")) {
//trying to unsubscribe; validate email address
if ($_POST['email'] == " "){
header("location: mailinglistform.php");
exit;
}
//connect to database
doDB( );
//check that email is in list
emailChecker($_POST['email']);
//get number of results and do action
if (mysql_num_rows($check_result) < 1) {
//print failure message
$display_block = "<P>Couldn't find your address!</P>
<P>No action was taken.</P>";
} else {
//unsubscribe the address
$id = mysql_result($check_result, 0, "id");
$sql = "delete from subscribers where id = '$id' ";
$result = mysql_query($sql, $conn) or die(mysql_error( ));
$display_block = "<P>You're unsubscribed!</p>";
}
}
?>
</div>
<h1><img src="shopPhilly.GIF" alt="shopPhilly" /></h1>
<ul id = "links">
<li> <a id="bag3" href="shopPhillyindex.php"><img src="blank.gif" alt="Home"></a></li>
<li> <a id="bag1" href="shopPhillyStores.php"><img src="blank.gif" alt="Store Info"></a></li>
<li> <a id="bag2" href="shopPhillyCalendar.php"><img src="blank.gif" alt="Calendar"></a></li>
<li> <a id="bag4" href="shopPhillyStyle.php"><img src="blank.gif" alt="Style Guide"></a></li>
</ul>
<div id = "disclaimer">
<a href="http://hawk.csc.villanova.edu/~f05g04/prototype/contactUs.html">Contact Us!</a> |
<a href="http://hawk.csc.villanova.edu/~f05g04/prototype/adminlogin.html">Administrator Login</a> <br>
<p>This website was created as a Senior Project in <a href="http://www.csc.villanova.edu/%7Ejoyce/csc4790/f05/index.html">CSC 4790</a>
at <a href="http://www.villanova.edu">Villanova University</a>.
</p>
<?php echo "$display_block"; ?>
</body>
</html>