zahidprimex Posted July 28, 2008 Share Posted July 28, 2008 I have used these codes to show data from database. <?php$con = mysql_connect("localhost","root","");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("zahid", $con);$result = mysql_query("SELECT * FROM person");echo "<table border='1'><tr><th>Firstname</th><th>Lastname</th><th>Button</th></tr>";while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "<td>" . "<input type='button' name='action' value='Action'></input>" . "</td>"; echo "</tr>"; }echo "</table>";mysql_close($con);?> The result of this code isNow how can i set action for these buttons?Sorry I have posted it in ASP section.Moderators are requested to move it to right section. Link to comment Share on other sites More sharing options...
jeffman Posted July 28, 2008 Share Posted July 28, 2008 That sort of action means javascript. There's a very thorough discussion of connecting events (like clicking a button) to javascript functions here. Link to comment Share on other sites More sharing options...
zahidprimex Posted July 28, 2008 Author Share Posted July 28, 2008 That sort of action means javascript. There's a very thorough discussion of connecting events (like clicking a button) to javascript functions here.I want to delete record from mysql database by clicking on this button..Is it possible to do it with javascript? Link to comment Share on other sites More sharing options...
Synook Posted July 28, 2008 Share Posted July 28, 2008 You'll need to use JavaScript to link to an ASP page (through AJAX or plain location assignment) that performs the DELETE. Link to comment Share on other sites More sharing options...
justsomeguy Posted July 28, 2008 Share Posted July 28, 2008 You don't even need to use Javascript or a button, it can just be a link. echo "<td><a href=\"delete.php?lastname={$row['LastName']}\">Delete</a></td>";Of course, you'll want to use something more unique than a last name. If you have a unique ID in the database that would work better, or else you would delete everyone with the same last name. Link to comment Share on other sites More sharing options...
zahidprimex Posted July 29, 2008 Author Share Posted July 29, 2008 You don't even need to use Javascript or a button, it can just be a link. echo "<td><a href=\"delete.php?lastname={$row['LastName']}\">Delete</a></td>";Of course, you'll want to use something more unique than a last name. If you have a unique ID in the database that would work better, or else you would delete everyone with the same last name.Thanks for your help.But what will be the code of delete.php ? Link to comment Share on other sites More sharing options...
justsomeguy Posted July 29, 2008 Share Posted July 29, 2008 Whatever you want it to be. You can get the value of variables sent in the querystring using $_GET, to get the lastname variable you would use $_GET['lastname']. You can use that value to do a query on your database to delete the record. On pages that do things like insert, update, or delete, you'll also want to make sure the user has permission to do that. Link to comment Share on other sites More sharing options...
zahidprimex Posted July 29, 2008 Author Share Posted July 29, 2008 Whatever you want it to be. You can get the value of variables sent in the querystring using $_GET, to get the lastname variable you would use $_GET['lastname']. You can use that value to do a query on your database to delete the record. On pages that do things like insert, update, or delete, you'll also want to make sure the user has permission to do that.I have done it.Thanks a lot for you help boss.I also thank Synook & Deirdre's Dad for their help. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.