我想刪除已添加的數據庫中的一行,但是當我嘗試單擊我的index.php中的刪除按鈕時,它說刪除了記錄,但是當我單擊確定時,未刪除的記錄,這裏是我的代碼:使用php刪除數據庫中的一行
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);
?>
這是我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>
我缺少什麼,和什麼我應該刪除並添加?
您是否收到任何錯誤消息? – TAAPSogeking
嘗試更改此行「to 。 onclick部分可能會與帖子混淆 – TAAPSogeking