hiaw Posted February 16, 2007 Share Posted February 16, 2007 Hi, I have a simple form for inserting new data into mysql. then directly below it I list all the data in a table. I would like to add an edit button to the end of the row so the user can just click the edit button for the corresponding row and it will get the data from mysql and put them into the form. I also want a delete button next to the edit button. But I can't seem get more than 1 form action in a page. Help? I used this to submit the form into the page itself. <form action="<? $_SERVER['PHP_SELF'] ?>" method="post"> I use the following code to get all the table from mysql. while($row = mysql_fetch_array($result)){ echo "<tr>"; for($i = 0; $i < mysql_num_fields($result); $i++){ echo "<td>". $row[$i] ."</td>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/38835-solved-editdelete-mysql-data/ Share on other sites More sharing options...
AdRock Posted February 17, 2007 Share Posted February 17, 2007 I used this when i first started using PHP so it may be some use or may not. You could improve it but at least it can delete and edit records using the same page <div id="content" class="style3"> <table> <tr><td>Click <a href="addrecord.php"><img border="0" src="../images/add1.gif "></a> to add new page content</td></tr> <tr><td> </td></tr> <tr><td colspan="2" style="border: 1px solid;"><em>Please note that once an article has been deleted, it is NOT recoverable</em></td></tr> <tr><td> </td></tr> <?php $db = mysql_connect("localhost", "******", "******"); // Connect to SQL database with username and password mysql_select_db("*******",$db); // The database name $result = mysql_query("SELECT * FROM content ORDER BY title ASC",$db); // Scan Database using SQL query string echo mysql_error($db); while ($row = mysql_fetch_array($result)){?> <tr><td><?echo $row['title'];?></td> <td><a href="delete.php?id=<? echo $row['id']; ?>"><img border="0" src="../images/delete1.gif "></a> <td><a href="edit.php?id=<? echo $row['id']; ?>"><img border="0" src="../images/edit1.gif "></a> </td></tr> <?} // Closes While Loop ?> </table> </div> Quote Link to comment https://forums.phpfreaks.com/topic/38835-solved-editdelete-mysql-data/#findComment-186742 Share on other sites More sharing options...
ataria Posted February 17, 2007 Share Posted February 17, 2007 Your script is... unique. and, just do.. page.php?page=edit page.php?page=delete so the script would look like.. if ($page == "delete") { //all the stuff to delete } if ($page == "edit") { // all the stuff to edit. } if (!$page){ // normal page } Quote Link to comment https://forums.phpfreaks.com/topic/38835-solved-editdelete-mysql-data/#findComment-186752 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.