从数据库中删除php

时间:2013-11-24 20:00:45

标签: 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;
    }
   ?>
  <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>

当我继续提交时没有任何反应...... 当我选择一个选项,当我按删除从数据库行删除时,我想要... 帮助plizzz朋友..

1 个答案:

答案 0 :(得分:0)

假设“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_query。

在你的mysql语句中添加“或者死mysql_error()”,这样当某些东西不起作用时,你会得到一条错误信息,帮助你找出问题所在。