我试图让表单更新我的SQL数据库中的表但是我收到此错误
如果我的客户ID字段有" 7020"作为值和证明字段为" test"我收到此错误:无法更新数据:未知列'测试'在'字段列表'
</head>
<body>
<?php
if(isset($_POST['update']))
{
$dbhost = 'xxxxxxxx';
$dbuser = 'xxxxx';
$dbpass = 'xxxxxxxxxxxxxxxxxxxxxxxx';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$clientid = $_POST['clientid'];
$proof = $_POST['proof'];
$sql = "UPDATE penalties ". "SET Proof = $proof " ."WHERE client_id = $clientid AND type='ban'";
mysql_select_db('b3bot');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($conn);
}
else
{
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Client ID</td>
<td><input name="clientid" type="text" id="clientid"></td>
</tr>
<tr>
<td width="100">Proof</td>
<td><input name="proof" type="text" id="proof"></td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td width="100"> </td>
<td>
<input name="update" type="submit" id="update" value="Update">
</td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
答案 0 :(得分:2)
您尝试执行的SQL查询应该是错误的。正如我所见,现在的查询看起来像:
UPDATE penalties SET Proof = sth WHERE client_id = test AND type='ban'
应该是:
<强> UPDATE penalties SET Proof = 'sth' WHERE client_id = 'test' AND type='ban'
强>
(注意引号)