本文介绍了无法使用php从数据库中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过使用php文件从mysql数据库中删除条目,由于某种原因,它不起作用.该连接(在"connect.php"中)有效,因为我在SELECT语句中使用了相同的文件,并且这些有效.我只是在删除它们时遇到了麻烦.有什么想法我做错了吗?预先感谢!

I am trying to delete entries from a mysql database by using a php file and for some reason it doesn't work. The connection (in "connect.php") works, as I am using the same file for my SELECT statements and those work. I am only having trouble with deleting them. Any ideas what I'm doing wrong?Thanks in advance!

<?php
include "include/connect.php";

if($link === false){
    die("ERROR: Could not connect. " . mysql_connect_error());
}

$word = (isset($_GET['email']) ? $_GET['email'] : null);

$sql = "DELETE * from tbl_sbs WHERE eml='" . word . "'";
$result = mysql_query($sql);
?>

推荐答案

除非WHERE子句中的过滤目的与SELECT语句相同,否则,请勿将*或列名用于DELETE语句.应该是

You don't use * or column name for DELETE statement unless in WHERE clause for filtering purpose same as in SELECT statement. It should just be

$sql = "DELETE from tbl_sbs";

DELETE通用语法是

DELETE FROM TABLE_NAME WHERE COLUMN_NAME <comparison_operator> SOME_FILTER_CONDITION

所以,在您的情况下应该只是

So, in your case it should just be

$sql = "DELETE FROM tbl_sbs WHERE eml='" . $word . "'";

错误报告会向您抛出未定义的常量单词通知; IF ,这不是'" . word . "'中的错字.

Error reporting would have thrown you an undefined constant word notice; IF that wasn't a typo in '" . word . "'.

*并检查了错误之后,将引发以下情况:

The * and having checked for errors, would have thrown you the following:

参考文献:

  • https://dev.mysql.com/doc/refman/5.0/en/delete.html
  • http://php.net/manual/en/function.error-reporting.php
  • http://php.net/manual/en/function.mysql-error.php

这篇关于无法使用php从数据库中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 08:17
查看更多