Forum Moderators: coopster
<?
$title=$_POST['title'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$degree=$_POST['degree'];
$interest=$_POST['interest'];
$checkbox=$_POST['checkbox'];
include("example_include.php");
$link=mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
mysql_select_db("$dbDatabase") or die( "Unable to select database");
$query="INSERT INTO example (
clientid,
title,
fname,
lname,
address1,
address2,
city,
state,
zip,
phone,
email,
degree,
interest,
checkbox,
)
VALUES(
'',
'$title',
'$fname',
'$lname',
'$address1',
'$address2',
'$city',
'$state',
'$zip',
'$phone',
'$email',
'$degree',
'$interest',
'$checkbox',
)";
$result = mysql_query($query) or $errors[] = mysql_error();
header ("Location: [example.com...]
?>
header ("Location: http://example.com/thanks.html");
Since it is a sql error and not a php error the php is not stopping. Its going ahead with the redirecting.
Temporary rem out the redirect so you can see the sql errors. Better yet make your mysql_query echo the sql on die so that you see where your sql syntax is off.
something like this
$result = mysql_query($query) or die ('Query Failed<br>'.$sql.'<br>'.mysql_error().'<br>');
require_once("DB.php");
$dbtype = "mysql";
$dbserver = "localhost";
$dbuser = "myuser";
$dbpassword = "mypassword";
$dbdatabase = "mydatabase";
$dsn = "$dbtype://$dbuser:$dbpass@$dbserver/$dbdatabase";
$db =& DB::connect($dsn);
if (DB::isError($db))
{
print($db->getMessage());
exit;
}
$MyTable = "table";
# AutoExecute takes an array of $Name => $Value pairs and makes an insert for you...perfect for $_POST (if all the fields posted are in the db)
$Result = $db->autoExecute($MyTable,$_POST,DB_AUTOQUERY_INSERT);
I usually put all my form fields in an array by doing name="FormField[FieldName]" for each field, then passing $_POST['FormField'] into autoExecute, that way if I have some values in the form that aren't in the db, they won't get thrown in there and cause errors.
Check out PEAR's DB module, it makes everything so much easier and cleaner.
[pear.php.net...]