Edit/Delete records with Radio buttons

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Rmias
Forum Newbie
Posts: 24
Joined: Wed Nov 26, 2003 11:02 am

Edit/Delete records with Radio buttons

Post by Rmias »

Hi guys,

Can some one help me with this please, I wrote a simple user authentication program and the next thing I would like to do is edit or delete each user. Below is the PHP code to display all the users in the database. I would like to add a Radio button in front of each users and when I select one user using the Radio button and click on edit or delete button a new page will be open with the selected users details and I will be able to edit or delete this users. Also I would like to display an error message if none is selected and clicked on one of the buttons. Could you please advise me on how to implement this.

Thank you for all your help.

<html>
<head>
<link rel=stylesheet href="StyleInterface.css" type="text/css">
<title>Users</title>
</head>
<body>
<h2>Users Account</h2>

Code: Select all

<?php

	mysql_connect("localhost") or die ("Unable to connect to databse.");

	mysql_select_db("users") or die ("Unable to select database.");

	$resultID = mysql_query("SELECT * FROM users");

	print "<table border=1><tr><th>User ID</th>";
	print "<th>Full Name</th><th>User Name</th><th>Password</th><th>Email Address</th><th>Application ID</th>";

	while ($row = mysql_fetch_row($resultID))
	{
		print "<tr>";
		foreach ($row as $field)
		{
			print "<td>$field</td>";
		}
		print "</td>";

	}

	print "</table>";
?>
</body>
</html>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

if each record has a (real unique) id you can add input/radio fields all with the same name and each with the id of the record as value.
When the form is submitted you can re-query the record by the id submitted.

Code: Select all

print "<table border=1><tr><td>edit/delete</th><th>User ID</th>";
print "<th>Full Name</th><th>User Name</th><th>Password</th><th>Email Address</th><th>Application ID</th>";

while ($row = mysql_fetch_row($resultID))
{
	print "<tr>";
	// the user-id is the first field?
	echo  '<td><input type="radio" name="user_id" value="', $row[0], '"/></td>';
	foreach ($row as $field)
	{
		print "<td>$field</td>";
	}
	print "</tr>";
}
print "</table>";
Rmias
Forum Newbie
Posts: 24
Joined: Wed Nov 26, 2003 11:02 am

Edit/Delete Radio button

Post by Rmias »

Thanks volka I will try it

Happy Christmas and New Year
Post Reply