Jump to content

[SOLVED] edit/delete mysql data


hiaw

Recommended Posts

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>";
}
}

Link to comment
https://forums.phpfreaks.com/topic/38835-solved-editdelete-mysql-data/
Share on other sites

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>&nbsp</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>&nbsp</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>

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.