I've put together the code below that lists and allows me to delete members.
Solution
<?php
$db_host = 'hostname';
$db_user = 'username';
$db_pwd = 'password';
$database = 'databasename';
$table = 'tablename';
// use the same name as SQL table
if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");
if (!mysql_select_db($database))
die("Can't select database");
function sql_safe($s)
{
if (get_magic_quotes_gpc())
$s = stripslashes($s);
return mysql_real_escape_string($s);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (isset($_POST["submit"]))
{
if (isset($_POST['del']))
$userid = intval($_POST['del']);
if (mysql_query("DELETE FROM {$table} WHERE userid={$userid}"))
$msg = 'The member who you selected has now been deleted!';
else
$msg = 'Could not delete the selected member';
}
}
?>
<html><head>
<title>Save Photo(s) to Find</title>
<style type="text/css">
<!--
.style1 {
color: #FFFFFF;
font-size: 18px;
font-family: Calibri;
}
.style2 {
font-size: 18px;
font-weight: bold;
font-family: Calibri;
}
.style3 {font-family: Calibri}
.style6 {font-size: 16px}
.style7 {font-family: Calibri; font-size: 16px; }
-->
</style>
</head>
<body>
<p class="style7">
<?php
if (isset($msg)) // this is special section for
// outputing message
{
?></p>
<p class="style7">
<?=$msg?>
</p>
<?php
}
?>
<form action="<?=$PHP_SELF?>" method="POST" enctype="multipart/form-data">
<?php
$result = mysql_query("SELECT userid, forename, surname, subscriptionexpiration FROM {$table} ORDER BY userid DESC");
if (mysql_num_rows($result) == 0) // table is empty
echo 'There are no members to view';
else
{
echo "<table>\n";
while(list($userid, $forename, $surname, $subscriptionexpiration) = mysql_fetch_row($result))
{
echo "<tr>\n"
."<td><input type='radio' name='del' forename, surname value='{$userid}' /></td>\n"
."<td><small>{$forename} {$surname}</small><td>\n"
."<td><small>{$subscriptionexpiration}</small><td>\n"
."</tr>\n";
}
echo "<tr><td colspan=\"3\">";
echo '<input type="submit" value="Delete Selected Member" name="submit"/>';
echo "</td></tr>";
echo '</table>';
}
?>
<input type="hidden" name="action" id="action" />
</form>
</body>
</html>
To make it a little easier for me, I'd like to be able to insert the outputted list into a table on my form with the first column containing the bullet point, radio button and name of the member and the last column to show the 'Subscription Expiration Date'.
I've tried to simply move the php script into the table columns but this simply doesn't work because I can't, or should I say, don't know how to incorporate the PHP and HTML elements together.
don't know how to incorporate the PHP and HTML elements together.What do you mean? You already did it in the code you posted...