MySQL 错误 1064:您的 SQL 语法有错误……靠近第 1 行?
MySQL Error 1064: You have an error in your SQL syntax .. near line 1?
我正在做一个 MySQL & PHP 项目。它基于音乐数据库。当我转到 http://andrewb1.sgedu.site/editgenres.php:
时出现以下错误
Error: SQL Error:
Errno: 1064
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 '' at line 1
我有点困惑我是如何在第 1 行收到错误的,因为唯一的错误是打开的 php 标签
editgenres.php 的代码是:
<?php
include 'dbconnect.php';
$sql = "select * from Genres where GenreID = " . $_REQUEST['GenreID'];
if (!$result = $mysqli->query($sql)) {
echo "Error: SQL Error: </br>";
echo "Errno: " . $mysqli->errno . "</br>";
echo "Error: " . $mysqli->error . "</br>";
exit;
}
$row = $result->fetch_assoc();
?>
<form action="editgenressrv.php">
<input type="hidden" name="GenreID" value = "<?php echo $row["GenreID"]?>"/>
GenreID:<input type="text" name="GenreID" value="<?php echo $row["GenreID"]?>"/></br>
GenreName:<input type="text" name="GenreName" value="<?php echo $row["GenreName"]?>"/></br>
<input type="submit"/>
</form>
此外,如果需要,这里是 EditGenresSrv.php 的代码:
include 'dbconnect.php';
$sql = "update Genres set ";
$sql .= "GenreID = '" . $_REQUEST["firstname"] ."'," ;
$sql .= "GenreName = '" . $_REQUEST["lastname"] ."'," ;
$sql .= "where GenreID= " . $_REQUEST['GenreID'];
if (!$result = $mysqli->query($sql)) {
echo "Error: SQL Error: </br>";
echo "Errno: " . $mysqli->errno . "</br>";
echo "Error: " . $mysqli->error . "</br>";
exit;
}
?>
<script>
window.location='genres.php';
</script>
如果需要,这里是 dbconnect.php(尽管我已经测试过了并且没问题):
include 'dbconnect.php';
$sql = "insert into students (firstname,lastname,email) values (" .
"'" . $_REQUEST["GenreID"] ."','" .
$_REQUEST["GenreName"] . "' ";
if (!$result = $mysqli->query($sql)) {
echo "Error: SQL Error: </br>";
echo "Errno: " . $mysqli->errno . "</br>";
echo "Error: " . $mysqli->error . "</br>";
exit;
}
?>
<script>
window.location='genres.php';
</script>
这是 HTM 文件:
<form action="addgenressrv.php">
GenreID:<input type="text" name="GenreID"/></br>
GenreName:<input type="text" name="GenreName"/></br>
<input type="submit"/>
</form>
注意 where 前的逗号。
$sql = "update Genres set ";
$sql .= "GenreID = '" . $_REQUEST["firstname"] ."'," ;
$sql .= "GenreName = '" . $_REQUEST["lastname"] ."' " ;
$sql .= "where GenreID= " . $_REQUEST['GenreID'];
您需要将 GenreID 传递到您的页面,查看以下内容 link
http://andrewb1.sgedu.site/editgenres.php?GenreID=1
你就会明白一切。如果没有,那么我会向您解释。
您上一页的 $_REQUEST['GenreID']
应该有价值。
$sql = "select * from Genres where GenreID = " . $_REQUEST['GenreID'];
这一行给出了错误消息,因为您没有将 GenreID
传递给文件 editgenres.php
,无论是使用 POST 方法还是 GET。
在您的表单中输入 <form action="editgenres.php">
然后
GenreID:<input type="text" name="GenreID"/></br>
GenreName:<input type="text" name="GenreName"/></br>
因为你说 editgenres.php
错误所以你必须通过上面的表格调用这个页面。检查第一页的 操作 ,它将调用 http://andrewb1.sgedu.site/editgenres.php
我正在做一个 MySQL & PHP 项目。它基于音乐数据库。当我转到 http://andrewb1.sgedu.site/editgenres.php:
时出现以下错误Error: SQL Error:
Errno: 1064
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 '' at line 1
我有点困惑我是如何在第 1 行收到错误的,因为唯一的错误是打开的 php 标签
editgenres.php 的代码是:
<?php
include 'dbconnect.php';
$sql = "select * from Genres where GenreID = " . $_REQUEST['GenreID'];
if (!$result = $mysqli->query($sql)) {
echo "Error: SQL Error: </br>";
echo "Errno: " . $mysqli->errno . "</br>";
echo "Error: " . $mysqli->error . "</br>";
exit;
}
$row = $result->fetch_assoc();
?>
<form action="editgenressrv.php">
<input type="hidden" name="GenreID" value = "<?php echo $row["GenreID"]?>"/>
GenreID:<input type="text" name="GenreID" value="<?php echo $row["GenreID"]?>"/></br>
GenreName:<input type="text" name="GenreName" value="<?php echo $row["GenreName"]?>"/></br>
<input type="submit"/>
</form>
此外,如果需要,这里是 EditGenresSrv.php 的代码:
include 'dbconnect.php';
$sql = "update Genres set ";
$sql .= "GenreID = '" . $_REQUEST["firstname"] ."'," ;
$sql .= "GenreName = '" . $_REQUEST["lastname"] ."'," ;
$sql .= "where GenreID= " . $_REQUEST['GenreID'];
if (!$result = $mysqli->query($sql)) {
echo "Error: SQL Error: </br>";
echo "Errno: " . $mysqli->errno . "</br>";
echo "Error: " . $mysqli->error . "</br>";
exit;
}
?>
<script>
window.location='genres.php';
</script>
如果需要,这里是 dbconnect.php(尽管我已经测试过了并且没问题):
include 'dbconnect.php';
$sql = "insert into students (firstname,lastname,email) values (" .
"'" . $_REQUEST["GenreID"] ."','" .
$_REQUEST["GenreName"] . "' ";
if (!$result = $mysqli->query($sql)) {
echo "Error: SQL Error: </br>";
echo "Errno: " . $mysqli->errno . "</br>";
echo "Error: " . $mysqli->error . "</br>";
exit;
}
?>
<script>
window.location='genres.php';
</script>
这是 HTM 文件:
<form action="addgenressrv.php">
GenreID:<input type="text" name="GenreID"/></br>
GenreName:<input type="text" name="GenreName"/></br>
<input type="submit"/>
</form>
注意 where 前的逗号。
$sql = "update Genres set ";
$sql .= "GenreID = '" . $_REQUEST["firstname"] ."'," ;
$sql .= "GenreName = '" . $_REQUEST["lastname"] ."' " ;
$sql .= "where GenreID= " . $_REQUEST['GenreID'];
您需要将 GenreID 传递到您的页面,查看以下内容 link
http://andrewb1.sgedu.site/editgenres.php?GenreID=1
你就会明白一切。如果没有,那么我会向您解释。
您上一页的 $_REQUEST['GenreID']
应该有价值。
$sql = "select * from Genres where GenreID = " . $_REQUEST['GenreID'];
这一行给出了错误消息,因为您没有将 GenreID
传递给文件 editgenres.php
,无论是使用 POST 方法还是 GET。
在您的表单中输入 <form action="editgenres.php">
然后
GenreID:<input type="text" name="GenreID"/></br>
GenreName:<input type="text" name="GenreName"/></br>
因为你说 editgenres.php
错误所以你必须通过上面的表格调用这个页面。检查第一页的 操作 ,它将调用 http://andrewb1.sgedu.site/editgenres.php