If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2

Thread: PHP error

  1. #1
    Junior Member
    Join Date
    Nov 2005
    Member #
    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" "">

    <link rel="stylesheet" type="text/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" />

    <div id="content">

    <h2> Join Our Mailing List! </h2>


    //set up a couple of functions
    function doDB( ) {
    global $conn;
    //open the connection
    $conn = mysql_connect("", "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>

    <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>

    } else if (($_POST['op'] == "ds") && ($_POST['action'] == "sub")) {
    //trying to subscribe; validate email address
    if ($_POST['email'] == " ") {
    header("Location: mailinglistform.php");
    //connect to database
    doDB( );
    //check that email is in list

    //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");
    //connect to database
    doDB( );

    //check that email is in list

    //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>";



    <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>

    <div id = "disclaimer">

    <a href="">Contact Us!</a> |
    <a href="">Administrator Login</a> <br>

    <p>This website was created as a Senior Project in <a href="">CSC 4790</a>
    at <a href="">Villanova University</a>.

    <?php echo "$display_block"; ?>


  3. #2
    Senior Member jbagley's Avatar
    Join Date
    Sep 2004
    Cape Town
    Member #
    Firstly, instead of this
    use this
    Also replace this
    <input type=\"hidden\" name=\"op\" value=\"ds\">
    with this
    <input type='hidden' id='op' name='op' value='ds'>

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
All times are GMT -6. The time now is 04:34 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: