PHP + MySQL:在Insert中找不到语法错误

时间:2015-11-06 17:33:30

标签: php mysql

我是PHP的新手。我用其他语言编程;但对于这个项目,我主要只是重用其他代码。

无论如何,我认为自己对MySql感到满意,并且几乎每天都在使用它。然而;这个PHP脚本给了我很多麻烦。 MySql报告的语法错误似乎是一个非常好的查询。我想,只是在这里寻找第二双眼睛。我好像疯了。这是下面的代码:

<html>

<body>

<?php

$con = mysql_connect("xxxxxxxx","xxxxxxx","xxxxxxxx"); 

//if (!$con)
//  {
//  die('Could not connect: ' . mysql_error());

mysql_select_db("reiajam1", $con); 

$result = mysql_query("SELECT itemid FROM tenants ORDER BY itemid DESC LIMIT 1");

$row = mysql_fetch_array($result);


echo "Tenant Successfully Added.";

$highestrow = $row[0];
$x = $highestrow + 1;
echo $x;

$sql = mysql_query("INSERT INTO tenants (itemid, first, last)
VALUES
($x,'$_POST[fname]','$_POST[lname]')");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('49','$_POST[arrested]',$x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('50','$_POST[arrested_date]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('51','$_POST[arrested_charge]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('52','$_POST[arrested2]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('53','$_POST[arrested_date2]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('54','$_POST[arrested_charge2]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('55','$_POST[arrested_3]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('56','$_POST[arrested_date3]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('57','$_POST[arrested_charge3]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('16','$_POST[ll1]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('18','$_POST[ll2]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('26','$_POST[ll3]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('27','$_POST[evicted]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('28','$_POST[evic_address]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('29','$_POST[evic_date]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('30','$_POST[evic_by]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('31','$_POST[evic_damage]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('39','$_POST[evicted_2]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('40','$_POST[evicted_from2]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('42','$_POST[evicted_date_2]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('44','$_POST[evicted_by_2]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('46','$_POST[evicted_damage_claimed_2]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('37','$_POST[ssn]', $x)");

$sql = mysql_query("INSERT INTO field_data (fieldid, data_txt, itemid)
VALUES
('20','$_POST[notes]', $x)");

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }


mysql_close($con)

?>

</body>

</html>

1 个答案:

答案 0 :(得分:1)

我建议你去看看每个变量,看看什么是空的

这样

echo fname;
echo lname;