0

我有点卡住了。我不断收到语法错误。任何人都可以看看,让我知道出了什么问题吗?

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“return (Badge, Dept, Asset) VALUES ('61584', 'IT', 12345)' 附近使用正确的语法

<?php
$dept = $_GET['dept'];
$badge = $_GET['badge'];
if (empty($badge)) {
             echo '<center> You must insert a value into the Badge field </center>';
    }
    else {
foreach($_GET['asset'] as $key => $value) {
            $db=mysql_connect ("localhost",  "USER", "PASSWORD") or die ('I cannot connect  to  the database because: ' . mysql_error());
            $mydb=mysql_select_db("radios") or die ('I cannot select that table' . mysql_error());
#                mysql_query("INSERT INTO return  (Badge, Dept, Asset)  VALUES (test, test, test)") or die ('Can not write to DB because: ' . mysql_error());
            mysql_query("INSERT INTO return (Badge, Dept, Asset)  VALUES ('$badge', '$dept', $value)") or die ('<body style="background-color:red">' . mysql_error());
echo $value;
echo '<br>';
            }
echo '<body style="background-color:green">';

}
?>
<html>
    <head>
            <title>Radio return</title>



    </head>
    <body>
            <form action="index.php" method="get" id="badgeform">
            <center> Badge: <input type="text" name="badge" id="badgefield"/>
            <script>document.getElementById('badgefield').focus()</script>
            <center> Dept: <input type="text" name="dept" id="deptfield"/>
            <center> Asset: <input type="text" name="asset[1]" id="assetfield"/>
            <center> Asset: <input type="text" name="asset[2]" id="assetfield"/>
            <center> Asset: <input type="text" name="asset[3]" id="assetfield"/>
            <center> Asset: <input type="text" name="asset[4]" id="assetfield"/>
            <center> Asset: <input type="text" name="asset[5]" id="assetfield"/>
            <center> Asset: <input type="text" name="asset[6]" id="assetfield"/>
            <center> Asset: <input type="text" name="asset[7]" id="assetfield"/>
            <center> Asset: <input type="text" name="asset[8]" id="assetfield"/>
            <center> Asset: <input type="text" name="asset[9]" id="assetfield"/>
            <center> Asset: <input type="text" name="asset[10]" id="assetfield"/>
            <center> Asset: <input type="text" name="asset[11]" id="assetfield"/>
            <center> Asset: <input type="text" name="asset[12]" id="assetfield"/>
            <center> Asset: <input type="text" name="asset[13]" id="assetfield"/>
            <center> Asset: <input type="text" name="asset[14]" id="assetfield"/>
            <center> Asset: <input type="text" name="asset[15]" id="assetfield"/>
            <center> Asset: <input type="text" name="asset[16]" id="assetfield"/>
            <center> Asset: <input type="text" name="asset[17]" id="assetfield"/>
            <center> Asset: <input type="text" name="asset[18]" id="assetfield"/>
            <center> Asset: <input type="text" name="asset[19]" id="assetfield"/>
            <center> Asset: <input type="text" name="asset[20]" id="assetfield"/>
            <input type="submit"> </center>
            </form>


    </body>


</html>
4

2 回答 2

4

RETURN is a reserved keyword.

Use INSERT INTO `return` (B...

于 2013-09-27T16:20:39.673 回答
2

Your table is named as a MySQL reserved word. meaning you should try something like this.

INSERT INTO `return` ....

Read More

于 2013-09-27T16:20:57.723 回答