-1

很抱歉上次问了我的功能问题类型问题。我是 Stackoverflow.com 的新手,也是 php 的新手,这就是为什么。

我想问的是:

我已经创建了一个管理员帐户。会员有注册页面,因此会员将注册。当用户在数据库表中注册时,我将有一个字段初始化 0 值,这意味着他没有被批准。在管理员帐户中,我有获取成员列表的代码。代码如下:

<h2><?php echo "User list"; ?></h2>

        <table border="0" cellpadding="0" cellspacing="0">
                <tr bgcolor="#f87820">
                        <td><img src="img/blank.gif" alt="" width="10" height="25"></td>
                        <td class="tabhead"><img src="img/blank.gif" alt="" width="150" height="6"><br><b><?php echo "first name"; ?></b></td>
                        <td class="tabhead"><img src="img/blank.gif" alt="" width="150" height="6"><br><b><?php echo "lastname name"; ?></b></td>
                        <td class="tabhead"><img src="img/blank.gif" alt="" width="150" height="6"><br><b><?php echo "member id"; ?></b></td>
                        <td class="tabhead"><img src="img/blank.gif" alt="" width="50" height="6"><br><b><?php echo "delete"; ?></b></td>
                        <td><img src="img/blank.gif" alt="" width="10" height="25"></td>
                </tr>

                <?php

                                                }

                        $result=mysql_query("SELECT member_id,firstname,lastname,login FROM members ORDER BY firstname");
                        $i = 0;
                        while($row = mysql_fetch_array($result)) {
                                if ($i > 0) {
                                        echo "<tr valign='bottom'>";
                                        echo "<td bgcolor='#ffffff' height='1' style='background-image:url(img/strichel.gif)' colspan='6'></td>";
                                        echo "</tr>";
                                }
                                echo "<tr valign='middle'>";
                                echo "<td class='tabval'><img src='img/blank.gif' alt='' width='10' height='20'></td>";
                                echo "<td class='tabval'><b>".$row['lastname']."</b></td>";
                                echo "<td class='tabval'>".$row['firstname']." </td>";
                                echo "<td class='tabval'>".$row['member_id']." </td>";

                                echo "<td class='tabval'><a onclick=\"return </span></a></td>";
                                echo "<td class='tabval'></td>";
                                echo "</tr>";
                                $i++;
                        }

                ?>

        </table>


in this i wanna add tho more things in the table 1 to delete a member and 2 to have approved or denied option for that i made two functiom

below code is to delete

if($_REQUEST['action']=="del")
{
$memberId = mysql_real_Escape_string($_REQUEST['member_id']);
mysql_query("DELETE FROM members WHERE member_id=$memberId");
}

以下为批准成员

但我的问题是我不知道如何在表中包含一个按钮或单选按钮,可以将值删除或批准传递给这些函数。

请告诉我添加此按钮的语法如何,以便批准我可以将我在数据库中提供的值 0 更改为 1 以便成员获得批准。

4

2 回答 2

1

尝试这个:

echo '<td><a href="http://yourwebsite/yourscriptname.php?action=del&amp;member_id='
   . htmlspecialchars($row['member_id']) . '">Delete</a>';
if ($row['approved'] == 0) {
    echo '&nbsp;<a href="http://yourwebsite/yourscriptname.php?action=approve&amp;member_id='
       . htmlspecialchars($row['member_id']) . '">Approve</a>';
}
echo '</td>';

并确保所有数据库值都在 htmlspecialchars() 中发送到浏览器。

另一方面,

$member_id = 0;
if (isset($_GET['member_id'])) $member_id = intval($_GET['member_id']);
$action = '';
if (isset($_GET['action'])) $action = $_GET['action'];

$sql = '';
switch($action) {
case 'approve':
    $sql = "UPDATE members SET approval = 1 WHERE member_id = $member_id";
    break;
case 'delete':
    $sql = "DELETE FROM member WHERE member_id = $member_id";
    break;
}
if (!empty($sql) && !empty($member_id)) {
    // execute the sql.
}
于 2008-12-12T04:11:21.847 回答
0

我要做的是在表格内设置一个表格。

?> <form name="deleteUser" id="deleteUser" method="post" action=""> <input type="hidden" name="member_id" id="member_id" value="<?php echo $row['member_id'] ?> <input type="submit" name="action" id="action" value="del" /> </form><?php

我会在你的<td>标签之间插入它。

<td class='tabval'>INSERT HERE</td>";

于 2008-12-12T04:01:41.430 回答