Register

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
    Posts
    4
    Member #
    11964
    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>

  2.  

  3. #2
    Senior Member jbagley's Avatar
    Join Date
    Sep 2004
    Location
    Cape Town
    Posts
    845
    Member #
    7422
    Firstly, instead of this
    Code:
    $_POST['op']
    use this
    Code:
    @$_POST['op']
    Also replace this
    Code:
    <input type=\"hidden\" name=\"op\" value=\"ds\">
    with this
    Code:
    <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 08:42 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com