基本上如我的问题所述,它适用于phpmyadmin,但不适用于php本身。当我运行脚本时,它会返回true,并且不会死亡。帮帮我!mysql DELETE在phpmyadmin上工作,但不在php脚本上
这里是查询:
DELETE FROM selections WHERE selectorID = '$userID' AND selectedID = '$ID'
下面是PHP脚本:
<?php
include_once "connect_to_mysql.php";
$errorB = false;
$error = '';
$id = '';
$userID = '';
if (empty($_GET['ID']) || empty($_GET['userID'])) {
$errorB = true;
if (empty($_GET['ID'])) {
$error = $error.'-No selected ID was sent';
}
if (empty($_GET['userID'])) {
$error = $error.'-No selector ID was sent';
}
} else {
$id = $_GET['ID'];
$userID = $_GET['userID'];
echo $id.$userID;
$sqlInsert = mysql_query("DELETE FROM selections WHERE selectorID = '$userID' AND selectedID = '$ID'") or die (mysql_error());
echo 'shz';
}
if ($errorB) {
echo $error;
}
?>
我的数据库看起来是这样的:
id|selectorID|selectedID
3 1 4
4 1 5
如果它在phpmyadmin工作,而不是在PHP我的猜测是你的变量不包含你期望他们的值。您还需要将其分解为最简单的用例场景,以便于进行故障排除。 – 2013-02-20 15:09:17
你知道你的代码在sql注入的情况下非常不安全吗?在传递给你的sql查询之前,你应该验证从'$ _GET'得到的所有数据。 – oktopus 2013-02-20 15:12:13