我有点卡住了。我一直收到语法错误。任何人都可以看看,让我知道什么是错的?
您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便在第1行的'return(徽章,部门,资产)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>