Page 1 of 1

Edit/Delete records with Radio buttons

Posted: Tue Dec 23, 2003 4:25 am
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>

Posted: Wed Dec 24, 2003 1:09 am
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>";

Edit/Delete Radio button

Posted: Wed Dec 24, 2003 4:54 am
by Rmias
Thanks volka I will try it

Happy Christmas and New Year