日期:2014-05-17  浏览次数:20500 次

这个插入SQL的代码有什么错误码?
在DW写的PHP代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<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'

?>
</body>
</html>


为什么总是报错:
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());
?>