您的 SQL 语法有错误;当我尝试编辑记录时,请检查与您的 MySQL 服务器版本相对应的手册,以便在第 7 行的 '' 附近使用正确的语法,而不是出现错误请有人告诉我为什么会这样吗?
<?php
$db = mysql_connect('localhost','root','') or die('unable to connect');
mysql_select_db('demo',$db) or die(mysql_error($db));
?>
<html>
<head>
<title>Commit</title>
</head>
<body>
<?php
switch($_GET['action']){
case 'add';
switch($_GET['type']){
case 'student';
$query = 'insert into student
(student_name,streamid,book1,book2)
values
("'. $_POST['student_name'] . ' ",
' . $_POST['stream'] . ' ,
' . $_POST['book1'] . ' ,
' . $_POST['book2'] . ' )';
break;
}
break;
case 'edit';
switch ($_GET['type']){
case 'student';
$query = 'UPDATE student SET
student_name = " ' . $_POST['student_name'] . ' " ,
streamid = ' . $_POST['stream'] . ' ,
book1 = ' . $_POST['book1'] . ' ,
book2 = ' . $_POST['book2'] . '
WHERE
st_id =' . $_POST['st_id'];
break;
}
break;
}
if(isset($query)){
$result = mysql_query($query,$db) or die(mysql_error($db));
}
echo 'done';
?>
</body>
</html>