The code I am using (below) doesn't work for some reason, I check everything matches in the html form - I just can't figure this out.
Could I be getting the error because something that is wrong on the HTML side? I'm using the jQuery form validator (this works fine) could this cause problems? http://jqueryvalidation.org/
<?php
$host="localhost"; // Host name
$username="USERNAME"; // Mysql username
$password="PASSWORD"; // Mysql password
$db_name="DBNAME"; // Database name
$tbl_name="Persons"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Get values from form
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$company=$_POST['company'];
$email=$_POST['email'];
$registered=$_POST['registered'];
$percentage=$_POST['percentage'];
$products=$_POST['products'];
$prize=$_POST['prize'];
$terms=$_POST['terms'];
$newsletter=$_POST['newsletter'];
// Insert data into mysql
$sql="INSERT INTO $tbl_name(FirstName, LastNname, Company, EmailAddress, Registered, PercentOfBusiness, ProductsSold, WhichPrize, Newsletter)VALUES('$fname', '$lname', '$company', '$email', '$registered', '$percentage', '$products', '$prize', '$terms', '$newsletter')";
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='insert.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
?>
<?php
$result = mysql_query($query) or die(mysql_error());
?>
<?php
// close connection
mysql_close();
?>
$sql");` – Dave Jun 07 '13 at 14:09