doumei9589 2013-10-06 16:20
浏览 52

使用php删除数据库中的行

I want to delete a row in a database that I have added but when i try to click the delete button in my index.php it says record deleted but when I click ok, it does not delete the record, here are my codes:

index.php:

$con = mysql_connect("localhost","pma");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("class_schedule", $con);

$result = mysql_query("SELECT * FROM schedule");

?>
<center>
<table border="1" width="800">
<tr>
<td colspan='8'><input type="text" width='300'/>
<input type="button" value="Search" onclick="location='search.php'" />
<input type="button" value="View All" onclick="window.location.href=''"/>
<input type="button" value="Add" onclick="location='add.php'"/></td>
</tr></table>

<?php
echo "<center><table border='1' width='800'>
<tr>
    <td><center>Time</td>
        <td><center>Subject</td>
    <td><center>Course</td>
    <td><center>Section</td>
        <td><center>Day</td>
    <td><center>Room</td>

</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['time'] . "</td>";
echo "<td>" . $row['subject'] . "</td>";
echo "<td>" . $row['course'] . "</td>";
echo "<td>" . $row['section'] . "</td>";
echo "<td>" . $row['day'] . "</td>";
echo "<td>" . $row['room'] . "</td>";

?>


<td><input type="submit" value="Edit" name="edit" />
<form action="delete.php" method="post">
<input type="submit" value="Delete" name="delete" onclick="location='delete.php'" />
</td>
</form>
<?php
echo "</tr>";
}
echo "</table></center>";

mysql_close($con);
?>

And this is my delete.php:

<?php

    require "connect.php";
    $deltime=$_POST["deltime"];
    mysql_query("DELETE FROM schedule WHERE deltime='$deltime'");
    mysql_close($con);
?>
<div>
<p align="center"><b>Record Deleted</b><br/>
<form method="post">
    <center><input type="submit" name="submit" value="Ok" formaction="index.php" /></center>
</form>
</p></div></form>

What am I missing, and what should I remove and add?

  • 写回答

3条回答 默认 最新

  • douduidui1046 2014-05-08 09:23
    关注

    Modify the following line

    mysql_query("DELETE FROM schedule WHERE deltime='$deltime'");
    

    As

    mysql_query("DELETE FROM schedule WHERE deltime='$deltime'", $con);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比