
March 8th, 2000, 10:40 PM
|
|
Registered User
|
|
Join Date: Feb 2000
Location: Chicago IL, USA
Posts: 16
Time spent in forums: 1 h 27 m 54 sec
Reputation 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
|