mysql - Deleting a row in a database using php -
i want delete row in database have added when try click delete button in index.php says record deleted when click ok, not delete record, here 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 * 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 delete.php
:
<?php require "connect.php"; $deltime=$_post["deltime"]; mysql_query("delete schedule 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 missing, , should remove , add?
your id not getting in delete.php
file remove delete button , replace code:
<td><a href="delete.php? id=<?php echo $row['id'];?>">delete</td>
Comments
Post a Comment