这个插入SQL的代码有什么错误码?
在(本文来)源gaodaimacom搞#^代%!码&网(
搞gaodaima代码
DW写的PHP代码
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″ />
<body>
<?php
mysql_connect(‘localhost’,’root’,’778692′);
mysql_query(“set names gbk”);
mysql_select_db(‘test’);
INSERT INTO `test`.`votes` (
`id` ,
`sport` ,
`ballot`
)
VALUES (
‘4’, ‘乒乓球’, ‘0’
)
?>
为什么总是报错:
Parse error: syntax error, unexpected ‘INTO’ (T_STRING) in C:\xampp\htdocs\toupiaopiao\result.php on line 15
——解决方案——————–
哥们这个代码不对啊, insert into 是个sql语句,怎么可以直接那样写呢?
$sql=”insert into … “;
mysql_query($Sql,$conn); //conn是链接的对象 $conn=mysql_connect(‘localhost’,’root’,’778692′);
sql语句正确性 你可以直接先在数据库中判断
——解决方案——————–
$sql =<<< SQL
INSERT INTO `test`.`votes` (
`id` ,
`sport` ,
`ballot`
)
VALUES (
‘4’, ‘乒乓球’, ‘0’
)
SQL;
mysql_query($sql);
——解决方案——————–
- PHP code
<?php mysql_connect("localhost", "mysql_user", "mysql_password") or die("Could not connect: " . mysql_error()); mysql_select_db("mydb"); mysql_query("INSERT INTO mytable (product) values ('kossu')"); printf ("Last inserted record has id %d\n", mysql_insert_id());?>