Jump to content

[SOLVED] storing email address into table


bradkenyon

Recommended Posts

This is probably extremely easy, but I'll appreciate any help.

I have created a two column table, "id" and "address".

I want to a input box someone can type in their email address, and when they hit the submit button, it will be stored into the table "email_test".

<input type="text" name="address"> <input type="submit">

Now what?

Thanks in advance for reading this.
Link to comment
Share on other sites

you first need to connect to the database....

which can look like this

[code]
<?php
    $usr = "username";
    $pwd = "password";
    $db = "database name";
    $host = "localhost";

    $cid = mysql_connect($host,$usr,$pwd);
    mysql_select_db($db);
    if (!$cid) { echo("ERROR: " . mysql_error() . "\n");    }

?>

[/code]

Then need to the form and this code...you might have to tweak it a bit

[code]
<?php
  
    # back on to this page (POST METHOD)
    if ($REQUEST_METHOD=="POST") {
        
        $SQL = " INSERT INTO email_test ";
        $SQL = $SQL . " (address, ) VALUES ";
        $SQL = $SQL . " ('$address') ";
                
        #execute SQL statement
        $result = mysql_db_query($db,"$SQL",$cid);
        
        # check for error
        if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n");    }
        
     echo ("<P><B>Your Request Was Submitted Successfully!!!</B></P>\n");

    }
    mysql_close($cid);
?>
[/code]

should get you started.....
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.