php文件中的语法错误和未知错误

时间:2015-03-12 14:31:59

标签: php mysql

我试图从我的数据库中删除stock item,但我一直收到此错误,我无法理解如何修复它。有任何想法吗?

这是错误:

  

"删除的详细信息如下:   注意:未定义索引:第17行/var/www/vhosts/c2agolf.candept.com/httpdocs/Conor/test/delete/delete.php中的itemdescription项目描述:   SQL查询中存在错误:SQL语法中存在错误;检查与您的MySQL服务器版本相对应的手册,以便在''删除'附近使用正确的语法。 = 1 WHERE itemdescription ='数组[itemdescription]''在第1行"

这是我的代码:

<head>
<link rel = "stylesheet" type = "text/css" href = "deletestock.css">
<link href='http://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'>
</head>

<body>
<div id = "content">
<div class = "transBox">
<input type = "button" id = "MenuBtn" value = "Menu" onClick = "window.location = 'c2agolf.candept.com/menu.html';">

<?php
include("dbconnect.php");

$sql = "UPDATE Stock SET 'delete' = 1 WHERE itemdescription = '$_POST [itemdescription]' ";

echo "The details deleted are as follows: <br>";
echo  "<label><b>Item Description : </b> " . $_POST['itemdescription'] . "<br></label>";

if(!mysql_query($sql,$conn))
    {
        die("There was an error in the SQL Query: " . mysql_error());
    }

    echo "<script> alert('The stock has been deleted'); </script>";
    mysql_close($conn);
?>

<form action = "delete.html.php" method = "POST">
<br>

    <input type = "submit" value = "Return to Insert Page">

</form>

1 个答案:

答案 0 :(得分:1)

$_POST[itemdescription]之间有空格...&#34;删除&#34;是一个关键字,如果它被用作列名,则应使用反引号进行转义...

尝试更改:

$sql = "UPDATE Stock SET 'delete' = 1 WHERE itemdescription = '$_POST [itemdescription]' ";

为:

$sql = "UPDATE Stock SET `delete` = 1 WHERE itemdescription = '" . $_POST['itemdescription'] . "' ";

或:

$itemdescription = $_POST['itemdescription'];
$sql = "UPDATE Stock SET `delete` = 1 WHERE itemdescription = '$itemdescription' ";