A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearmember control through admin account using php - page 1
User InfoPosts
member control through admin account using php#1
I am new to php.
I made a member registration on login page and adm too. So inside admin I wanted to get the list of the members and delete the members I dont want. So I took the a code from a sample code for phone book from http://localhost/xamp and editted it to my requirement I am able to retrieve the members but unable to delete the members. See the code below:



require_once('../config.php');

//Array to store validation errors
$errmsg_arr = array();

//Validation error flag
$errflag = false;

//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}


?>







<body>
&nbsp;<p>

<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 $TEXT['phonebook-attrib1']; ?></b></td>
<td class="tabhead"><img src="img/blank.gif" alt="" width="150" height="6"><br><b><?php echo $TEXT['phonebook-attrib2']; ?></b></td>
<td class="tabhead"><img src="img/blank.gif" alt="" width="150" height="6"><br><b><?php echo $TEXT['phonebook-attrib3']; ?></b></td>
<td class="tabhead"><img src="img/blank.gif" alt="" width="50" height="6"><br><b><?php echo $TEXT['phonebook-attrib4']; ?></b></td>
<td><img src="img/blank.gif" alt="" width="10" height="25"></td>
</tr>

<?php
$firstname=$_REQUEST['firstname'];
$lastname=$_REQUEST['lastname'];
$phone=$_REQUEST['phone'];


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

$result=mysql_query("SELECT member_id,firstname,lastname,login FROM members ORDER BY lastname");
$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']."&nbsp;</td>";
echo "<td class='tabval'>".$row['member_id']."&nbsp;</td>";

echo "<td class='tabval'><a onclick=\"return confirm('".$TEXT['userlist-sure']."');\" href='userlist.php?action=del&amp;member_1d=".$row['member_id']."'><span class='red'>[".$TEXT['userlist-button1']."]</span></a></td>";
echo "<td class='tabval'></td>";
echo "</tr>";
$i++;
}

echo "<tr valign='bottom'>";
echo "<td bgcolor='#fb7922' colspan='6'><img src='img/blank.gif' alt='' width='1' height='8'></td>";
echo "</tr>";


?>

</table>


</body>




I haven't editted it that properly and the looks in all.

Please help me in making it able to delete the members also.

I didn't understand what .$TEXT['userlist-button1'].,'".$TEXT['userlist-sure']. variables are?
I also want to include an approved and disapproved radio button in table for each members.

How can I do that?

Please if you can help me.

posted date: 2008-12-08 00:35:00


Re: member control through admin account using php#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-08 00:35:01


Re: member control through admin account using php#3
This should be a POST via a FORM not a href link (GET).$TEXT is obviously an array holding the text you want printed.You need to replace &amp;member_1d in the href with a real & and a real i as &member_id.

posted date: 2008-12-08 00:46:00


Re: member control through admin account using php#4
$TEXT is an array contaning all the language strings for the selected language.You find the strings defined unter /lang/yourlanguage.phpIn general this is not a very good example to start coding with IMO.But I think your app may start working, if you make sure, the language files and other include files are available and you change this &amp;member_1d with &member_id

posted date: 2008-12-08 00:49:00


Re: member control through admin account using php#5
English, please.

posted date: 2008-12-08 00:51:00


Re: member control through admin account using php#6
i changed &amp;member_1d with &member_id but still code is not working i am getting the member list in the table but i am unable to delete the member with the link what to do?u have any other code?

posted date: 2008-12-08 02:02:00


Re: member control through admin account using php#7
Thank you, Gamecat.

posted date: 2008-12-08 05:18:00


Re: member control through admin account using php#8
where do you have your action? del?

posted date: 2008-12-10 15:34:00


Re: member control through admin account using php#9
An example of a list of members with delete links:$query = mysql_query("SELECT member_id,firstname,lastname,login FROM members ORDER BY lastname");if(mysql_num_row($query)!= 0){ //only continue if there are members in the databasewhile($row = mysql_fetch_assoc($query)){ //loop through each row in the database$member_id = $row['member_id'];$firstname = $row['firstname'];$lastname = $row['lastname'];echo '<p>' . $firstname . ' - <a href="delete_member.php?id='$member_id'">' delete '</a></p>';}}A simple script on delete_member.php to delete the member from the database.if(isset($_GET['id'])){$member_id = $_GET['id'];$query = mysql_query("DELETE FROM members WHERE member_id='$member_id'");echo '<p>This user was deleted from database</p>';}This code is only basic to give an example.I would however prefer to use a simple form and $_POST for something like this instead of using $_GET which is very vulnerable in this kind of instance.After getting the list of members use a form with input field to type the id you want to delete.

posted date: 2012-01-27 14:42:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.