您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在''违规','官员','日期','时间'附近使用正确的语法值('2101093','100','2','Daryl ','Coronad'在第1行
<?php
date_default_timezone_set('Asia/Manila');
$conn=mysql_connect("localhost","root","");
mysql_select_db("dbposo",$conn);
if(isset($_POST['add']))
{
$number=$_POST['id'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$age=$_POST['age'];
$gender=$_POST['gender'];
$violation=$_POST['violation'];
$officer=$_POST['officer'];
$date=date("y-m-d");
$time=date("H:i:s");
$violation=mysql_query("select count(number) as offensecount from tblcitizen where number='$number'",$conn);
if($data=mysql_fetch_array($violation))
{
$offensecount=$data['offensecount'];
if($offensecount==1)
{
mysql_query("insert into tblcitizen(number, price, offenses, fname, lname, age, gender,'violation','officer','date','time') values('$number','100','2','$fname','$lname','$age','$gender','$violation','$officer','$date','$time')",$conn) or die(mysql_error());
echo "<script>alert('2nd Offense: 300php Penalty!');</script>";
header('Refresh: 0; URL=admin_publicviolation.php');
}
else if($offensecount==2)
{
mysql_query("insert into tblcitizen(number, price, offenses, fname, lname,'age','gender','violation','officer','date','time') values('$number','500','3','$fname','$lname','$age','$gender','$violation','$officer','$date','$time')",$conn) or die(mysql_error());
echo "<script>alert('3rd Offense: 200php Penalty!');</script>";
header('Refresh: 0; URL=admin_publicviolation.php');
}
else if($offensecount==3)
{
mysql_query("insert into tblcitizen(number, price, offenses, fname, lname,'age','gender','violation','officer','date','time') values('$number','1000','4','$fname','$lname','$age','$gender','$violation','$officer','$date','$time')",$conn) or die(mysql_error());
echo "<script>alert('4th Offense: 1,000php Penalty!');</script>";
header('Refresh: 0; URL=admin_publicviolation.php');
}
else
{
echo "<script>alert('KUKULONG NA PO KAU SORRY PO!');</script>";
header('Refresh: 0; URL=admin_publicviolation.php');
}
}
}
else
{
header('location:admin_publicviolation.php');
}
?>
我的错误是什么?
答案 0 :(得分:0)
您不能用引号括起列名。要么使用刻度线,要么根本不使用(如果允许):
mysql_query("insert into tblcitizen(number, price, offenses, fname, lname, age,
gender,'violation','officer','date','time')
values('$number','100','2','$fname','$lname','$age','$gender','$violation','$officer','$date','$time')",$conn) or die(mysql_error());
应该是
mysql_query("insert into tblcitizen(number, price, offenses, fname, lname, age,
gender,`violation`,`officer`,`date`,`time`)
values('$number','100','2','$fname','$lname','$age','$gender','$violation','$officer','$date','$time')",$conn) or die(mysql_error());