我正在使用的代码(如下)由于某种原因不起作用,我检查了 html 表单中的所有匹配项 - 我只是无法弄清楚这一点。
我会因为 HTML 方面的问题而收到错误吗?我正在使用 jQuery 表单验证器(这很好用)这会导致问题吗? 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();
?>