MYSQL错误:MySQL server version for the right syntax to use near '1' at line 1
PHP插入数据$linkDB01=mysql_connect("local","amount","code");mysql_select_db("blueShine01"...
PHP插入数据
$linkDB01 = mysql_connect("local","amount","code");
mysql_select_db("blueShine01", $linkDB01);
mysql_query("set names utf8;");
$insert01 = mysql_query( "INSERT INTO barCodeTB01 (barCode, uploadTime, agencyName, queryTime, checkTime)VALUES('112233445566', '20140908', '哈哈', NOW(), '1') ");
//插入数据
if (!mysql_query($insert01,$linkDB01)) { die('Error: ' . mysql_error()); } else { echo "1 record added"; };
//询问是否插入数据成功
mysql_close($linkDB01);
数据可以成功插入,在数据库内能查到。但是同时的会页面也会返回
Error: You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '1' at line 1。
这句是什么意思?
噢···知道了
$insert01 = mysql_query( "INSERT INTO barCodeTB01 (barCode, uploadTime, agencyName, queryTime, checkTime)VALUES('112233445566', '20140908', '哈哈', NOW(), '1') ");
//赋值插入数据这一句是不能加mysql_query()的
改成:
$insert01 = "INSERT INTO barCodeTB01 (barCode, uploadTime, agencyName, queryTime, checkTime)VALUES('112233445566', '20140908', '哈哈', NOW(), '1')";
//这样就没问题了萌萌哒~~ 展开
$linkDB01 = mysql_connect("local","amount","code");
mysql_select_db("blueShine01", $linkDB01);
mysql_query("set names utf8;");
$insert01 = mysql_query( "INSERT INTO barCodeTB01 (barCode, uploadTime, agencyName, queryTime, checkTime)VALUES('112233445566', '20140908', '哈哈', NOW(), '1') ");
//插入数据
if (!mysql_query($insert01,$linkDB01)) { die('Error: ' . mysql_error()); } else { echo "1 record added"; };
//询问是否插入数据成功
mysql_close($linkDB01);
数据可以成功插入,在数据库内能查到。但是同时的会页面也会返回
Error: You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '1' at line 1。
这句是什么意思?
噢···知道了
$insert01 = mysql_query( "INSERT INTO barCodeTB01 (barCode, uploadTime, agencyName, queryTime, checkTime)VALUES('112233445566', '20140908', '哈哈', NOW(), '1') ");
//赋值插入数据这一句是不能加mysql_query()的
改成:
$insert01 = "INSERT INTO barCodeTB01 (barCode, uploadTime, agencyName, queryTime, checkTime)VALUES('112233445566', '20140908', '哈哈', NOW(), '1')";
//这样就没问题了萌萌哒~~ 展开
1个回答
展开全部
最好是能够有代码行的错误信息,就是说明你哪行代码对应的SQL语句出的问题,这样更好分析。
根据代码,目测可能有以下问题:
1
pstmt=conn.prepareStatement("select username from user where username=?");
pstmt.setString(1,shopname);
这段中如果shopname是null的话执行结果可能有问题,所以最好先判断以下shopname是否非null。
2
String sql ="insert into shop(shopname,price,number,brand,date) values ('"+shopname+"','"+price+"','"+number+"','"+brand+",'"+date+"');";
这个段中是否都是字符型?,还有就是'"+brand+",少了一个引号
这样可以么?
根据代码,目测可能有以下问题:
1
pstmt=conn.prepareStatement("select username from user where username=?");
pstmt.setString(1,shopname);
这段中如果shopname是null的话执行结果可能有问题,所以最好先判断以下shopname是否非null。
2
String sql ="insert into shop(shopname,price,number,brand,date) values ('"+shopname+"','"+price+"','"+number+"','"+brand+",'"+date+"');";
这个段中是否都是字符型?,还有就是'"+brand+",少了一个引号
这样可以么?
追问
呃···这是啥子东西···代码行没有错误消息,就只有这么一句You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1。
你的回答我看不懂啊···T。T···
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |