Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从数据库中删除php_Php_Mysql - Fatal编程技术网

从数据库中删除php

从数据库中删除php,php,mysql,Php,Mysql,我在从数据库中删除时遇到问题。因此,我有: <?php include('createdb.php'); if(!empty ($_POST['tribuna'])) { $delete = mysql_query("DELETE FROM tb_tribuna WHERE id = '".$_POST['tribuna']."';"); header("Location:index.php?a=buy"); //redirect exit; } ?>

我在从数据库中删除时遇到问题。因此,我有:

  <?php
 include('createdb.php');
 if(!empty ($_POST['tribuna']))
 {
  $delete = mysql_query("DELETE FROM tb_tribuna WHERE id = '".$_POST['tribuna']."';"); 
header("Location:index.php?a=buy"); //redirect
exit;
    }
   ?>
  <form id="formid" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> 
       <label>Tribuna :</label> <select name="tribuna" class="tribuna">
       <option selected="selected">-Select-</option>
            <?php
   $sql=mysql_query("select id,tribune_number from tb_tribuna ");
  while($row=mysql_fetch_array($sql))
  {
      $id=$row['id'];
    $tribune_number=$row['tribune_number'];
    echo '<option value="'.$id.'">'.$tribune_number.'</option>';
     } ?>
   </select><br/><br/>
    <input name="delete" type="submit" id="delete" value="Delete">
  </form>
假设“createdb.php”具有正确的数据库连接信息:

$conn = mysql_connect("$host","$db_uid","$db_pwd");
mysql_select_db("$db", $conn);
使删除函数如下所示:

$sql = "DELETE FROM tb_tribuna WHERE id = '$_POST[tribuna]' ";
$result = mysql_query($sql, $conn) or die(mysql_error());
您需要将db连接传递到mysql\u查询


并在mysql语句中添加“or die mysql_error()”,以便在出现问题时,您会收到一条错误消息,帮助您指出问题所在。

发布数据后,
mysql_error()
会输出什么?你不能逃避它,所以这可能是你的问题。这个例子很容易注入。您应该使用准备好的语句,或者至少使用
mysql\u real\u escape()
。(尽管这也不是100%安全)。我推荐PDO。你的连接在哪里,选择db命令和错误输出?Jeroen到底是什么?我不明白…你能给我举个例子吗?帮帮忙@用户2993914选择我的答案作为您问题的答案