I'm working on a PHP script to submit the contents of a form to an email address as well as to a mySQL database. The form submits okay to my email but it doesn't submit to the database. I'm pretty sure it's connecting to database as well as the table. An error was generating about it not connecting until I changed an incorrect login name. phpMyADMIN was used to create the fields. Here is a copy of the prototype form...
<?php
//NAME VARIABLES
$sur=$_POST['sur'];
$first=$_POST['first'];
$last=$_POST['last'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$home=$_POST['homename'];
$comments=$_POST['comments'];
$to="[email protected]";
$webmaster="TriadFriendlyHomes";
$message="$sur $first $last is interested in the $home home. Their phone number is $phone
.\n Their email address is: $email\n They posted the following:\n $comments";
//VALIDATE FORM FIELDS
if ($_POST['email']) {
mail($to, "You have a potential homebuyer.", $message, "Wrom: QZAAFXISHJEXX
echo "Thanks for your inquiry!";
}
else {
echo "Please fill in your email address.";
}
//INSERT INFORMATION INTO DATABASE
$DBhost = "localhost";
$DBuser = "*******";
$DBpass = "*****";
$DBname = "Clients";
$table = "homebuyers";
mysql_connect($DBhost, $DBuser, $DBpass) or die("Unable to connect to database.");
mysql_select_db("$DBname") or die("Unable to select database $DBname");
$sql="INSERT INTO $table(first, last, email, phone, homename, comments) VALUES('".$_POST['$first']."', '".$_POST['$last']."','".$_POST['$email']."','".$_POST['$phone']."','".$_POST['$home']."')";
$results = mysql_query($sql);
mysql_close();
?> Believe it or not but the tech support people at my budget host solved the problem! I just needed to add 1 line at the bottom of my script before the mysql_close(); command. print $sql() Maybe this will help someone else. Thanks. :rocker:
<?php
//NAME VARIABLES
$sur=$_POST['sur'];
$first=$_POST['first'];
$last=$_POST['last'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$home=$_POST['homename'];
$comments=$_POST['comments'];
$to="[email protected]";
$webmaster="TriadFriendlyHomes";
$message="$sur $first $last is interested in the $home home. Their phone number is $phone
.\n Their email address is: $email\n They posted the following:\n $comments";
//VALIDATE FORM FIELDS
if ($_POST['email']) {
mail($to, "You have a potential homebuyer.", $message, "Wrom: QZAAFXISHJEXX
echo "Thanks for your inquiry!";
}
else {
echo "Please fill in your email address.";
}
//INSERT INFORMATION INTO DATABASE
$DBhost = "localhost";
$DBuser = "*******";
$DBpass = "*****";
$DBname = "Clients";
$table = "homebuyers";
mysql_connect($DBhost, $DBuser, $DBpass) or die("Unable to connect to database.");
mysql_select_db("$DBname") or die("Unable to select database $DBname");
$sql="INSERT INTO $table(first, last, email, phone, homename, comments) VALUES('".$_POST['$first']."', '".$_POST['$last']."','".$_POST['$email']."','".$_POST['$phone']."','".$_POST['$home']."')";
$results = mysql_query($sql);
mysql_close();
?> Believe it or not but the tech support people at my budget host solved the problem! I just needed to add 1 line at the bottom of my script before the mysql_close(); command. print $sql() Maybe this will help someone else. Thanks. :rocker: