MySQL Forums
Forum List  »  PHP

PHP and MySQL form problems
Posted by: Kevin Mielwocki
Date: June 14, 2005 07:07AM

This is my first post and I'm just starting out, but the information I've seen so far seems very helpful..on to the question. I'm working on a project to send a php form to me via email, but to validate the form and insert the information into a MySQL database first. The database is setup via phpMyAdmin and I've had various parts working here and there, but I can't seem to get more than one record to insert into the database and have the entire processing work properly. Also, when using $_SERVER['HTTP_REFERER'] on my server, it brings up an error even though the form and database reside on our server. Here's what I've got so far:

$fname = stripslashes($fname);
$lname = stripslashes($lname);
$phone = stripslashes($phone);
$fax = stripslashes($fax);
$email = stripslashes($email);
$message = stripslashes($message);
// initialize a variable to
// put any errors we encounter into an array
$errors = array();
// test to see if the form was actually
// posted from our form
if(!ereg($page, $_SERVER['HTTP_REFERER']))
$errors[] = "Invalid referer\n";
// check to see if a name was entered
if (!$_POST['fname'])
// if not, add that error to our array
$errors[] = "First Name is required";
if (!$_POST['lname'])
$errors[] = "Last Name is required";
if (!$_POST['phone'])
$errors[] = "Phone Number is required";
if (!$_POST['fax'])
$errors[] = "Fax Number is required";
if (!$_POST['email'])
$errors[] = "Email Address is required";
if (!$_POST['message'])
$errors[] = "Please leave a message or comments or tell us your intended use of the download.";
// if there are any errors, display them
if (count($errors)>0){
echo "<strong>ERROR:<br>\n";
foreach($errors as $err)
echo "$err<br>\n";
} else {
// no errors, so we continue
$link = mysql_connect("host", "username", "password");

$query = INSERT INTO table_name VALUES ('', 'fname', 'lname', 'phone', 'fax', 'email', 'message');
$result = mysql_query($query);

while ($line = mysql_fetch_array($result))
foreach ($line as $value)
print "$value\n";

$mailTo = "";
$msgSubject = "Tools Download Form Results";
$msgBody = "$fname\n, $lname\n, $phone\n, $fax\n, $email\n, $message\n";
mail ($mailTo, $msgSubject, $msgbody);
header ("Location: contactform.php");

Any help would be great. Thanks.

Options: ReplyQuote

Written By
PHP and MySQL form problems
June 14, 2005 07:07AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.