Jump to content

How To Set Action For Buttons


zahidprimex

Recommended Posts

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 is488d433d1a3c6.jpgNow 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

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

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...