Hello,
I am brand new to PHP and am working on a website coded by someone else. I am attempting to get form results to be written to a table (tblform) in a database. Although I am not getting any error messages when I test and complete the form online, the form contents appear to be going into a black hole of sorts, since they aren't being written as a database record.
Any assistance you can offer would be greatly appreciated, and I apologize in advance if the problem is something obvious that my lack of experience is causing me to miss! Thank you -- Lynn
Here is the code for the form:
<form method="post" action="test/thanks23.php">
<input type="text" size="50" name="name”>
<input type="text" size="3" name="age">
<input type="text" size="50" name="email">
<input type="text" size="50" name="address”>
<input type="text" size="50" name="city">
<input type="text" size="3" name="state">
<input type="text" size="5" name="zip">
<input type="text" size="50" name="country">
<input type="submit" value="Send" name="submit”>
<input type="reset" name="reset" value="Clear">
</form>
And here is the php code:
<?php # Script 8.5 - handle_submit_url.php
$message = '<font color="red">The following errors occurred:<br />';
$problem = FALSE;
if (!eregi ("[[:alpha:].' -]{3,50}$", stripslashes(trim($POST['name'])))) {
$problem = TRUE;
$name = $POST['name'];
$message .= '<p>Please enter a valid name.</p>';
}
if (!eregi ("[[:alnum:]][a-z0-9.-]@[a-z0-9.-]+.[a-z]{2,4}$", stripslashes(trim($POST['email'])))) {
$problem = TRUE;
$email= $POST['email'];
$message .= '<p>Please enter a valid email address.</p>';
}
if (!eregi ("[[:alnum:].' -]{2,50}$", stripslashes(trim($POST['address'])))) {
$problem = TRUE;
$email= $POST['address'];
$message .= '<p>Please enter a valid address.</p>';
}
if (!eregi ("[[:alpha:].' -]{2,40}$", stripslashes(trim($POST['city'])))) {
$problem = TRUE;
$name = $POST['city'];
$message .= '<p>Please enter a valid city.</p>';
}
if (!eregi ("[[:alpha:].' -]{2,2}$", stripslashes(trim($POST['state'])))) {
$problem = TRUE;
$name = $POST['state'];
$message .= '<p>Please enter a valid state.</p>';
}
if (!eregi ("[[:digit:].' -]{5,5}$", stripslashes(trim($POST['zip'])))) {
$problem = TRUE;
$email= $POST['zip'];
$message .= '<p>Please enter a valid zip code.</p>';
}
if (!eregi ("[[:alpha:].' -]{3,40}$", stripslashes(trim($POST['country'])))) {
$problem = TRUE;
$name = $POST['country'];
$message .= '<p>Please enter a valid country.</p>';
} /else {
$email = eregi_replace ("[[:alnum:]][a-z0-9.-]@[a-z0-9.-]+.[a-z]{2,4}$", '<a href="mailto:\0">Email</a>',stripslashes(trim($_POST['email'])));
}/
// validate text area here
if (!$problem) {
$dbuser="******";
$dbpass="";
$dbname="******";
$table="tblform";
$chandle = mysql_connect("MySQLHost", $dbuser, $dbpass)
or die("Connection Failure to Database");
mysql_select_db($dbname, $chandle) or die ($dbname . " Database not found. " . $dbuser);
$sqlquery="INSERT INTO $table VALUES('$POST[name]','$POST[age]','$POST[email]','$POST[address]','$POST[city]','$POST[state]','$POST[zip]','$POST[country]')";
mysql_db_query($dbname, $query1) or die("Failed Query of " . $query1);
echo '<h2> Thank you for signing up! </h2>';
} else {
echo $message;
echo '</font><p>Please go back and try again.</p>';
}
?>