Goon Posted August 10, 2008 Share Posted August 10, 2008 Using the following code I can retrieve information from a mysql table and have the results displayed on the same page. Is it possible to add a delete option next to each of the returned results to allow user to delete unwanted records <h3>Please select your vehicle type</h3> <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> Please select your vehicle type: <select name="vehicle"> <option value="car">Car</option> <option value="van">Van</option> <option value="truck">Truck</option> <option value="bus">Bus</option> </select> <br/> <br> <input type="submit" value ="Search for tyres"/> </form> <?php $vehicle = $_POST['vehicle'] ; if ( $vehicle == '' ) { // print "<br>no vehicle selected ..." ; } else { $host = "localhost"; $user = "root"; $password = "*****"; $database = "*****"; $table = "tyre"; $connection = mysql_connect($host, $user, $password) or die ("Couldn't connect to server"); $db = mysql_select_db($database, $connection) or die ("Couldn't connect to database"); $result = mysql_query("SELECT * FROM $table WHERE vehicle = '" . $vehicle . "'") or die(mysql_error()); print "<br>Available tyres for: $vehicle<br><br>" ; echo "<table border='1'>"; echo "<tr> <th>Vehicle</th> <th>Size</th> <th>Brand</th> <th>Price</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['Vehicle']; echo "<td>"; echo $row['Size']; echo "<td>"; echo $row['Brand']; echo "</td><td>"; echo $row['Price']; echo "</td></tr>"; } echo "</table>"; } Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 10, 2008 Share Posted August 10, 2008 Is it possible to add a delete option next to each of the returned results to allow user to delete unwanted records Yup. I suggest you output a link to a delete page and pass the ID of the vehicle (which you hopefully have) to the page in the URL. It'll then be a case of something like this: <?php $id = (int) $_GET['id']; mysql_query("DELETE FROM yourtable WHERE id=$id"); echo 'Vehicle successfully deleted ?> Of course, you may wish to use checkboxes instead so that more than one vehicle can be deleted at a time. Also, please remember to use tags around your code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.