我已將下面的代碼放在一起,並允許我刪除成員。將PHP輸出插入表中
解決方案
<?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>
爲了讓我輕鬆一點,我希望能夠與包含子彈點的第一列插入列表輸出到一個表我的形式,單選按鈕和成員名稱,最後一列顯示「訂購到期日期」。
我試着簡單地將php腳本移動到表格列中,但這不起作用,因爲我不能,或者應該說,不知道如何將PHP和HTML元素結合在一起。
'不知道如何將PHP和HTML元素結合在一起。「你是什麼意思?你已經在你發佈的代碼中做了它... – 2012-01-03 16:19:33
也許他問如何使它成爲一張桌子而不是列表? – Rooster 2012-01-03 16:24:08