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

Thread: PHP errors...

  1. #1
    Senior Member thuffner's Avatar
    Join Date
    May 2003
    Posts
    165
    Member #
    1363
    Does anyone know how to fix this error?

    http://hawk.csc.villanova.edu/~f05g0...nglistform.php


    Here is the PHP code:

    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/contactsheet.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_result0"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>
    It seems I need to define the variables somewhere. Any idea where it would be?

    Thanks!
    BondMovies.com - "Nobody Does It Better."

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    PHP Code:
    if  ($_POST[op] != "ds") { 
    Should be
    PHP Code:
    if  ($_POST['op'] != "ds") { 

  4. #3
    Junior Member
    Join Date
    Nov 2005
    Posts
    4
    Member #
    11964
    Your suggestion was right however im still getting an error on the webpage saying: Notice: Undefined index: op in H:\Projects\f05\f05g04\html\prototype\mailinglistf orm.php on line 41
    and I don't know where to define the index because I thought it is already defined where I have <input type=\"hidden\" name=\"op\" value=\"ds\">

    Here's the php code again:

  5. #4
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    If everything else works, try to set a '@' sign in front of $_POST in the offending line.

    It's normally a nusance warning caused by setting error reporting to include notices in your php.ini file.
    So, if everything else works, you can supress the 'unset' warning by adding the '@' sign in front of the warning
    S. Rosland

  6. #5
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Well, you can probably get rid of the error by doing a:
    PHP Code:
    if ( ! isset( $_POST['op'] ) || $_POST['op'] != 'ds' ) { 
    Also, you should try to be uniform in your HTML code, it makes it more legible. Either use all ""s around attributes, or all ''s, or all nothings. So instead of:
    HTML Code:
    <input type=text name=\"email\" size=40 maxlength=150>
    Do a:
    HTML Code:
    <input type=\"text\" name=\"email\" size=\"40\" maxlength=\"150\">
    Or:
    HTML Code:
    <input type='text' name='email' size='40' maxlength='150'>
    Also, if you want to be keeping XHTML in mind (even though I saw you're using HTML 4.01), you should never leave any unquoted attributes, as that becomes incorrect in XHTML.

    But the latter is just a coding style tip :-)


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 01:06 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com