我的php页面一直出现错误。当我提交表单时,它表示我没有授权查看php页面,当我把它放入sql查询测试时,它说它是错误#1064。我一直收到此错误消息,我不知道为什么。在查询测试中,我只是在之间放置信息。有人可以帮忙解决这个问题吗?
<html>
<head>
<meta charset="utf-8">
<title>Enquiry</title>
</head>
<body>
<?php
$name=$_POST['name'];
$email=$_POST['email'];
$phone = $_POST['phone'];
$radio = $_POST['radio'];
$enquiry = $_POST['enquiry'];
$user="root";
$password="";
$database="test";
mysql_connect('localhost',$user,$password) or die("Unable to connect to server");
mysql_select_db($database) or die("Unable to select database");
$query = "INSERT INTO Enquiry VALUES ('','$name','$email','$phone','$radio','$enquiry')";
mysql_query($query);
mysql_close();
?>
</body>
</html>
答案 0 :(得分:0)
假设数据库中的第一列是自动递增的主键,则需要将SQL更改为:
$sql = "
INSERT INTO Enquiry (
name,
email,
phone,
radio,
enquiry
) VALUES (
'$name',
'$email',
'$phone',
'$radio',
'$enquiry'
)
";
答案 1 :(得分:0)
<?php
$con= mysql_connect("localhost","root","") or die('Unable to connect to server:'mysql_error());
mysql_select_db("test",$con);
if(isset($_POST['submit']))
{
$name=test_input($_POST['name']);
$email=test_input($_POST['email']);
$phone = test_input($_POST['phone']);
$radio = test_input($_POST['radio']);
$enquiry = test_input($_POST['enquiry']);
$sql = "
"INSERT INTO `Enquiry`"." (
name,
email,
phone,
radio,
enquiry
)". "VALUES". "(
"$name",
"$email",
"$phone",
"$radio",
"$enquiry"
)
";
$res=mysql_query($sql);
if(!$res){
die('Could not enter data: ' . mysql_error());
}
echo 'your successfull msg goes here';
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = mysql_real_escape_string($data);
return $data;
}
?>
假设primaryid是自动递增的。试试这段代码