2008-12-12 8 views
-1

Désolé de demander à un outil ma question de type de question de fonctionnalité la dernière fois. Je suis nouveau à Stackoverflow.com et aussi au php c'est pourquoi.gestion des membres par admin utilisant php

Ce que je voulais poser est la suivante:

J'ai fait un compte administrateur. Les membres ont une page d'inscription pour qu'un membre s'enregistre. Lorsque l'utilisateur s'inscrit dans la table de la base de données, je vais avoir un champ pour lequel la valeur 0 sera initialisée, ce qui signifie qu'il n'est pas approuvé. Dans le compte administrateur j'ai le code pour obtenir la liste des membres. Le code est donné ci-dessous:

<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"); 
} 

ci-dessous un pour les membres d'approuver

Mais mon problème est que je ne sais pas comment inclure un bouton ou un bouton radio dans le tableau qui peut passer à la suppression de valeurs ou approuver à ces fonctions. S'il vous plaît dites-moi comment la syntaxe est d'ajouter ce bouton de sorte que pour approuver je peux changer la valeur 0 que j'ai donné dans la base de données à 1 pour que le membre soit approuvé.

Répondre

0

Ce que je ferais est de mettre en place un formulaire à l'intérieur de la table.

?> <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

J'insérerais que entre votre balise <td>.

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

1

Essayez ceci:

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>'; 

Et assurez-vous que toutes vos valeurs de base de données sont envoyées au navigateur dans htmlspecialchars().

Sur l'autre face,

$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. 
} 
Questions connexes