Forum Moderators: coopster
I'm having difficulty figuring out how to use the radio button's value to send a delete query. Here's what I have so far, and it is the last section --if($submit)--that doesn't work for me:
<?php
function dbConnect()
{//define the database connection information
$dbHost = "localhost";
$dbUser = "root";
$dbPass = "******";
$dbName = "poker";
//connect to the db server
$link = @mysql_connect($dbHost, $dbUser, $dbPass);
}?>
<?php
function displaynames()
{//define variables
$result = mysql_query("SELECT * FROM hosts");
if ($myrow = mysql_fetch_array($result))
{
echo "<form method='post' action='/poker/schedule/learn.php'>";
echo "<table border=1>";
echo "<tr><td>NAME</td><td>DELETE</td></tr>";
do
{
printf("<tr><td>%s</td><td><input type='radio' name='hostid' value=%s></td></tr>", $myrow["name"], $myrow["hostid"]);
}while ($myrow =mysql_fetch_array ($result));
echo "</table>";
echo "<input type='Submit' name='submit' value='delete'>";
}else{
echo "Sorry, no records were found!";
}
}?>
<?php
dbConnect();
displaynames();
?>
<?php
if ($submit)
{
$sql = "DELETE FROM hosts WHERE hostid=$hostid";
$result = mysqlquery($sql);
displaynames();
}
?>
So, how do I reference the value of the radio button named hostid? When I do a view source on the page, each radio button has the appropriate value assigned, I just need to reference it so that the appropriate row is deleted, then re-display the list.
Thanks for your help!
-Chris