在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
<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
$sql="insert into ... ";
mysql_query($Sql,$conn); //conn是链接的对象 $conn=mysql_connect('localhost','root','778692');sql语句正确性 你可以直接先在数据库中判断
`sport` ,
`ballot`
)
VALUES (
'4', '乒乓球', '0'
)
SQL;mysql_query($sql);
$sql="insert into votes(sport) values('羽毛球')";
mysql_query($Sql, $conn=mysql_connect('localhost','root','778692')); //conn是链接的对象 $conn=mysql_connect('localhost','root','778692');mysql_close();
?>
</body>
改成这样吗??
<?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());
?>