dongsanhu4784 2016-11-30 07:30
浏览 28

从数据库中删除行不起作用

I'm trying to make a function that would delete from a mysql database a record from a specific table specified by the user and the row which will be used in the WHERE clause depends on the table chose.

This is what I have:

 $table=$_POST['table'];
 $title=$_POST['title'];
 if($table=="clients")
     $row="fullname";
 else if($table=="books")
     $row="title";
 else if($table="actors")
     $row="fullname";
 else if($table="employees")
     $row="fullname";

 $result = mysqli_query($con,"DELETE from $table WHERE $row='{$title}'") or die (mysqli_error($con));

 if($result) {
     $_SESSION['updateinfo']='deleted';
     header("location:index.php");
 } else {
    $_SESSION['updateinfo']='not deleted!';
    header("location:index.php");
 } 

Well, it works fine when I try to delete from clients,books,actors, but it does not work for employees.

I get the message " deleted ", but its still there.No error, no nothing. Also I would have to add 10 more those tables, is there a better way to do this?

I tried to echo $table, $title and $row and it seems that the SELECT from the HTML form only passes to the PHP script the correct value for the first 3 options, for the rest of them it passes a wrong value, below is my html form

 <select name="table" style="padding:5px;margin:5px;width:200px;">
  <option value="clients" selected="selected">Clients</option>
  <option value="books">Books</option>
  <option value="actors">Actors</option>
  <option value="employees">Em</option>
  <option value="other1">smthother</option>
  <option value="other2">smtoher2</option>
</select>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 路易威登官网 里边的参数逆向
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
    • ¥50 需求一个up主付费课程