Jump to content


Photo

[SOLVED] storing email address into table


  • Please log in to reply
1 reply to this topic

#1 bradkenyon

bradkenyon
  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts

Posted 03 May 2006 - 01:10 AM

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.

#2 ichversuchte

ichversuchte
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 03 May 2006 - 01:25 AM

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

which can look like this

<?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");    }

?>


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

<?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); 
?> 

should get you started.....





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users