Lee-Bartlett Posted October 5, 2008 Share Posted October 5, 2008 Im not sure how to get this to work, i got the query, i got the database echoing all results, i just wanna add one more feild giving me the option of deleting that row. heres the code, <?php require_once("includes/db_connection.php"); ?> <?php $id = $_POST['id']; $name = $_POST['name']; $email = $_POST['email']; $buissnes_name = $_POST['buissnes_name']; $location = $_POST['location']; $type = $_POST['type']; $delete = mysql_query("DELETE FROM tblbasicform WHERE name='$name'"); $sql = "SELECT * from tblbasicform"; $res = mysql_query($sql) or die(mysql_error()); echo "<table border=2>"; echo "<tr> <td>Name</td><td>Email</td><td>Buissnes Name</td><td>Location</td><td>Free or Paid</td> </tr>"; while($row = MYSQL_FETCH_ARRAY($res)) { echo "<tr><td>".$row['name']."</td>"; echo "<td>".$row['email']."</td>"; echo "<td>".$row['buissnes_name']."</td>"; echo "<td>".$row['location']."</td>"; echo "<td>".$row['type']."</td></tr>"; } echo "</table><br>"; ?> <a href="userform.php">Submit a WIFI hotspot</a> Link to comment https://forums.phpfreaks.com/topic/127130-how-would-i-add-a-delete-row-button-to-this/ Share on other sites More sharing options...
Orio Posted October 5, 2008 Share Posted October 5, 2008 If I got you right, this should be what you're looking for: <?php require_once("includes/db_connection.php"); ?> <?php if(isset($_POST['name'])) { $name = $_POST['name']; //If this is not some admin page, validation must be added here!! (Anti SQL injection) //Also, the name column should hold unique values... I think it'd be better off using the id column for the query but that's your choice $delete = mysql_query("DELETE FROM tblbasicform WHERE name='$name'"); } $sql = "SELECT * from tblbasicform"; $res = mysql_query($sql) or die(mysql_error()); echo "<table border=2>"; echo "<tr> <td>Name</td><td>Email</td><td>Buissnes Name</td><td>Location</td><td>Free or Paid</td><td>Delete?</td></tr>"; while($row = MYSQL_FETCH_ARRAY($res)) { echo "<tr><td>".$row['name']."</td>"; echo "<td>".$row['email']."</td>"; echo "<td>".$row['buissnes_name']."</td>"; echo "<td>".$row['location']."</td>"; echo "<td>".$row['type']."</td>"; echo '<td><form action="'.basename($_SERVER['PHP_SELF']).'" method="POST"> <input type="hidden" name="name" value="'.$row['name'].'"><input type="submit"></form></td></tr>'; } echo "</table><br>"; ?> <a href="userform.php">Submit a WIFI hotspot</a> I've added a few notes as comments inside the code. Check them out. Orio. Link to comment https://forums.phpfreaks.com/topic/127130-how-would-i-add-a-delete-row-button-to-this/#findComment-657612 Share on other sites More sharing options...
Lee-Bartlett Posted October 5, 2008 Author Share Posted October 5, 2008 Ye i know not to use $ post atm this is a mock up of a admin page, given to me by my uncle so i would start to learn php Ty for help Link to comment https://forums.phpfreaks.com/topic/127130-how-would-i-add-a-delete-row-button-to-this/#findComment-657617 Share on other sites More sharing options...
Lee-Bartlett Posted October 5, 2008 Author Share Posted October 5, 2008 I must be missing somthing here, i tried to edit that so it deletes by ID instead. did i miss somthing ? <?php require_once("includes/db_connection.php"); ?> <?php if(isset($_POST['id'])) { $id = $_POST['id']; $delete = mysql_query("DELETE FROM tblbasicform WHERE id='$id'"); } $sql = "SELECT * from tblbasicform"; $res = mysql_query($sql) or die(mysql_error()); echo "<table border=2>"; echo "<tr><td>id</td> <td>Name</td><td>Email</td><td>Buissnes Name</td><td>Location</td><td>Free or Paid</td><td>Delete?</td></tr>"; while($row = MYSQL_FETCH_ARRAY($res)) { echo "<tr><td>".$row['id']."</td>"; echo "<td>".$row['name']."</td>"; echo "<td>".$row['email']."</td>"; echo "<td>".$row['buissnes_name']."</td>"; echo "<td>".$row['location']."</td>"; echo "<td>".$row['type']."</td>"; echo '<td><form action="'.basename($_SERVER['PHP_SELF']).'" method="POST"> <input type="hidden" id="id" value="'.$row['id'].'"><input type="submit"></form></td></tr>'; } echo "</table><br>"; ?> <a href="userform.php">Submit a WIFI hotspot</a> Link to comment https://forums.phpfreaks.com/topic/127130-how-would-i-add-a-delete-row-button-to-this/#findComment-657622 Share on other sites More sharing options...
Orio Posted October 5, 2008 Share Posted October 5, 2008 You replaced the "name" field in the input tag... One replacement too much Should be like this: <?php require_once("includes/db_connection.php"); ?> <?php if(isset($_POST['id'])) { $id = $_POST['id']; $delete = mysql_query("DELETE FROM tblbasicform WHERE id='$id'"); } $sql = "SELECT * from tblbasicform"; $res = mysql_query($sql) or die(mysql_error()); echo "<table border=2>"; echo "<tr><td>id</td> <td>Name</td><td>Email</td><td>Buissnes Name</td><td>Location</td><td>Free or Paid</td><td>Delete?</td></tr>"; while($row = MYSQL_FETCH_ARRAY($res)) { echo "<tr><td>".$row['id']."</td>"; echo "<td>".$row['name']."</td>"; echo "<td>".$row['email']."</td>"; echo "<td>".$row['buissnes_name']."</td>"; echo "<td>".$row['location']."</td>"; echo "<td>".$row['type']."</td>"; echo '<td><form action="'.basename($_SERVER['PHP_SELF']).'" method="POST"> <input type="hidden" name="id" value="'.$row['id'].'"><input type="submit"></form></td></tr>'; } echo "</table><br>"; ?> <a href="userform.php">Submit a WIFI hotspot</a> Orio. Link to comment https://forums.phpfreaks.com/topic/127130-how-would-i-add-a-delete-row-button-to-this/#findComment-657624 Share on other sites More sharing options...
Lee-Bartlett Posted October 5, 2008 Author Share Posted October 5, 2008 Ah hehe ty Link to comment https://forums.phpfreaks.com/topic/127130-how-would-i-add-a-delete-row-button-to-this/#findComment-657643 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.