#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 1999
    Location
    St.JOhn's, Newfoundland, Canada
    Posts
    7
    Rep Power
    0
    I am looking for some one to give me a simple script that will allow a user to enter their email address and have it stored in a mysql database.

    the table name is Email just show me where to put the other info.

    Thanks in Advance
    Tim
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    Chicago IL, USA
    Posts
    16
    Rep Power
    0
    <?php
    create a file named test.php3 with the everything between the ==== (don't include the ====) below in the file. You may have to fine tune the html form a bit.

    Note the hidden "action" field. When the form is submitted (via POST) the field $action is available. Pass that to the addEmailToDb function and do an insert into the db.

    If the $action field has no value (i.e., you just open the file in the browser) then it will execute the showForm() function, which will draw the form instead of inserting into the db.

    ===================================
    function addEmailToDb($email_addr){
    GLOBAL $PHP_SELF;
    $HOSTNAME = "your_host";
    $DB_LOGIN = "your_db_user";
    $DB_PASSWD = "your_password";
    $DB_NAME = "your_db_name";
    $db = mysql_connect($HOSTNAME, $DB_LOGIN, $DB_PASSWD);
    mysql_select_db($DB_NAME,$db);

    $sql = "Insert INTO email values('$email_addr')";
    $result = mysql_query($sql);
    if (! $result) {
    echo "an error occurred. email was not inserted into the db.";
    } else {
    echo "email was successfully inserted into the db.";
    }

    }

    function showForm() {
    echo "<html>n";
    echo "<head>n";
    echo "<title>Add Email</title>n";
    echo "</head>n";
    echo "<body bgcolor='#FFFFFF'>n";
    echo "<table width=100% height=75%><tr><td><center>n";
    echo "<table cellpadding=2><tr><td bgcolor=#b2b4f6><center>n";
    echo "<table cellpadding=20><tr><td bgcolor=#ffffff><center>n";
    echo "<form action='$PHP_SELF'>n";
    echo "<input type=hidden name=action value=add_email>n";
    echo "<table cellpadding=5 cellspacing=1>n";
    echo "<tr><td>Password </td><td> <input type=password name=email_addr></td></tr>n";
    echo "</table><p>n";
    echo "<input type=submit value='Enter' default>n";
    echo "<input type=reset value='Clear'><br>n";
    echo "</form>n";
    echo "</center></td></tr></table>n";
    echo "</center></td></tr></table>n";
    echo "</center></td></tr></table>n";
    echo "</body>n";
    echo "</html>n";
    }

    if ( $action == "admin") {
    addEmailToDb($email_addr);
    } else ( $action == "") {
    showForm();
    }

    ?>

    =======================================
    Hope this helps.

    michael

Similar Threads

  1. php script won't work inside "cgi-local" directory
    By Volitics in forum PHP Development
    Replies: 5
    Last Post: April 26th, 2004, 11:50 PM
  2. Replies: 9
    Last Post: February 26th, 2004, 05:55 PM
  3. Perl script converting GIF and JPG images to BMP ???
    By Deanna475 in forum Perl Programming
    Replies: 20
    Last Post: February 17th, 2004, 07:35 PM
  4. Replies: 2
    Last Post: February 11th, 2004, 12:03 AM
  5. How can I enable a power user to run this script?
    By Yamadatroy in forum Visual Basic Programming
    Replies: 2
    Last Post: January 19th, 2004, 10:39 PM

IMN logo majestic logo threadwatch logo seochat tools logo