member management by admin using php - php

Sorry for asking an implement my feature question type question last time. I am new to Stackoverflow.com and also to php that's why.
What I was trying to ask is:
I have made a admin account. Members have registration page so a member will register. When user registers in the database table I will have a field for which 0 value will be initialised which means he is not approved. In admin account I have code to get the list of members. The code is given below:
<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");
}
below one for approving members
But my problem is I don't know how to include a button or radio button in the table which can pass value delete or approve to these functions.
Please tell me how the syntax is to add this button so that for approving I can change the value 0 that I gave in the database to 1 so that member get approved.

Try this:
echo '<td><a href="http://yourwebsite/yourscriptname.php?action=del&member_id='
. htmlspecialchars($row['member_id']) . '">Delete</a>';
if ($row['approved'] == 0) {
echo ' <a href="http://yourwebsite/yourscriptname.php?action=approve&member_id='
. htmlspecialchars($row['member_id']) . '">Approve</a>';
}
echo '</td>';
And make sure ALL of your database values are being sent to the browser in htmlspecialchars().
On the flipside,
$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.
}

What I would do is to set up a form inside of the 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
I would insert that in between your <td> tag.
<td class='tabval'>INSERT HERE</td>";

Related

Submit Buttons in while loop

my problem may be easy for experienced users, but I'm stucked on it. So, here's the problem. I have submit buttons in while loop, they draw, but they don't react on click. Here's my piece of code.
`<?php
$zap_cmember = count_query("SELECT * FROM `users` WHERE `clan` = '".$member['id']."' AND clan_stat != 'Призывник'");
while ($cmember = mysql_fetch_array($zap_cmember))
{
$zap_gold = mysql_result(mysql_query("SELECT SUM(gold) FROM klog WHERE name = '".$cmember['name']."'"), 0);
$zap_online = mysql_num_rows(count_query("SELECT * FROM `online` WHERE `id_session`='".$cmember['id_user']."'"));
if ($zap_online > 0)
{
$img_on = "<td align='center' valign='middle' ><img src='images/ico_online.png' alt='онлайн' class='png' ></td>";
}
else
{
$img_on = "<td align='center' valign='middle' ><img src='images/ico_offline.png' alt='оффлайн' class='png' ></td>";
}
$i = 'set';
echo '<tr>
<td width="141" height="25" align="left" valign="middle" >'.$cmember['name'].' ['.lvl($cmember['exp']).']</td>
<td align="center" valign="middle" ><span class="text_main_4">'.$cmember['clan_stat'].'</span></td>
<td align="center" valign="middle" ><span class="text_main_4">-</span></td>
<td align="center" valign="middle" ><span class="text_main_4">'.$zap_gold.'</span></td>
<td align="center" valign="middle" ><span class="text_main_4">'.$cmember['glory'].'</span></td>
'.$img_on.'';
if($boss)
{echo '<td align="center" id = "'.$i.'" valign="middle"><input type="submit" name="bSet" value="Назначить"></span></td>'; }
$i++;
$player = $cmember;
'</tr>';
if (isset($_POST['bSet']))
{
echo 'works';
count_query("UPDATE users SET clan_stat='Вождь' WHERE id_user='".$player['id_user']."'");
$time = date('j.n.y H:i');
count_query("INSERT INTO `message` (`time`, `to`, `text`, `metka`) VALUES ('".$time."', '".$player['name']."', 'Вас выбрали главой клана <a href=clan.php>".$clan['name']."</a>', '6')");
echo "<script>location.href='clan.php'</script>";
}
}
?>
`
You need to put everything that you want to submit to a <form id="yid">... </form>, after that to put on the button the onclick="javascript:$('#yid').submit()" and the yid= the particular id of the form you want the button to submit.

Add next button showing more details of a specific record using PDO

I'm currently working on a project,the CRUD function is working fine and i'm nearly finished but there's only one problem that can't figure it on how to do it.my problem is that, i have an update button and the update function works fine when i clicked the update button it will a specific record that i chose my problem is that i want to add a next button so that when i clicked on the nejxt button it will show other details on that person.because in my project there are lot of details to be included so i need a next button so i can view the other details of that specific record that i chose..can somebody please help me with it?
here is my code
class.user.php
public function dataview($query)
{
$stmt = $this->db->prepare("SELECT * from login ORDER BY username");
$stmt->execute();
if($stmt->rowCount()>0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<tr>";
echo "<td> ".$row['user_id']." </td>";
echo "<td> ".$row['username']." </td>";
echo '<td><a target="_blank" onclick="pop_up(this)" href=VIEWSAMPLE.PHP?user_id='.$row['user_id'].'>'.$row["username"].'</a></td>';
echo "<td> ".$row['password']." </td>";
echo '<td><a style="float:left" target="_blank" href="update.php?user_id=' . $row["user_id"] . '>'.$row["username"].'"<input name="image" type="image" value="edit" onclick="pop_up(this)"><image src="image/EDIT.png" class="img-responsive" width="25px"></a>
<a style="float:left" href="delete.php?user_id=' . $row["user_id"] . '>"<input name="image" type="image" value="delete" onclick="return confirm(\'are you sure?\')"><image src="image/DELETE.png" class="img-responsive" width="25px"> </a></td>';
echo "</tr>";
}
}
else
{
echo "<tr>";
"<td>Nothing here...</td>";
"</tr>";
}
}
}
and here is my viewsample.php where i want to add a next button
<?php
include_once 'dbconfig.php';
$username = isset($_GET['username']) ? $_GET['username'] : '';
$password = isset($_GET['password']) ? $_GET['password'] : '';
$province = isset($_GET['province']) ? $_GET['province'] : '';
if(isset($_GET['user_id']))
{
$user_id = $_GET['user_id'];
extract($crud->getID($user_id));
}
?>
<body>
<button onclick="this.style.display='none';document.body.offsetHeight;window.print();this.style.display='inline';">Print</button>
<br />
<br />
<div id="Survey-view">
<div id="header">
</div>
<p><strong>INFORMATION</strong></p>
<hr />
<div id="main-frame">
<table id="information-content" cellspacing="0">
<thead>
<tr>
<th>Username</th>
<th>Password</th>
<th>Province</th>
</tr>
<tbody>
<tr>
<td><?php echo $username; ?></td>
<td><?php echo $password; ?></td>
<td><?php echo $province; ?></td>
</tr>
</tbody>
</thead>
</table>
</div>
<br />
<br />
In query, fetch next id from database.
then in viewsample.php file add following code.
Next
and in viewsample.php, get data based on id passed in $_GET['user_id']
use this query to fetch next id,
select * from table where id = (select min(id) from table where id > current id)

How do I hardcode a dynamic url to an image map?

I am working on a Zip Code search, and have successfully built the search. Now, I need to have the ability to click on an image map of a map, and hardcode an href to a dynamic URL
So for example, the search works well displaying contact information for a zip code in PA. But if I have an image map, I'd like the ability for it to display the same contact information if I click the image map of PA on the map image.
Here is the code I'm using to do the search, and at the bottom is the code I need help with for the image map.
<form action="search6.php" method="post">
<p><span class="orange16">Zip Code:</span>
<input type="text" name="search_name"> <input type="submit" value="Search" />
</p>
</form>
<br />
<table width="700" border="0">
<?php
if (isset($_POST['search_name'])) {
$search_name = $_POST['search_name'];
if (!empty($search_name)) {
if (strlen($search_name)>=5) {
$query = "SELECT * FROM `search4` WHERE `ZipCode` LIKE '%".mysql_real_escape_string($search_name)."%'";
$query_run = mysql_query($query);
if (mysql_num_rows($query_run)>=1) {
echo "<table width=700' border='0'>";
echo "<tr>";
echo "<td width='700' valign='top'><table width='100%' border='0'>";
echo "<tr>";
echo "<td><p><strong>Results found: </strong></p>";
while ($query_row = mysql_fetch_assoc($query_run)) {{
echo $query_row['ZipCode'].', ';
echo $query_row['ZipCity'].', ';
echo $query_row['ZipState'].'<br><br>';
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo '<span class="productdescription"><p>Office: </p></span></h2>';
echo $query_row['Office'].'<br>';
echo $query_row['Address1'].'<br>';
if(!empty($query_row['Address2'])) // This will skip if the field if it's empty
echo $query_row['Address2'].'<br>';
echo $query_row['City'].', ';
echo $query_row['State'].' ';
echo $query_row['Zip'].'<br>';
echo '<p><strong>Phone Number: </strong></p>';
echo $query_row['Phone'].'<br>';
echo '<p><strong>Fax Number: </strong></p>';
echo $query_row['Fax'].'<br><br>';
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</td>";
//BeginImage display result
$res=mysql_query("select * from Images");
{
echo "<td width='703' align='right' valign='top'>";?> <img src="<?php echo $query_row["Image"]; ?>"> <?php echo "</td>";
echo "</tr>";
}
//EndImage display result
echo ("<table width='700px' border='0' cellpadding='5' cellspacing='1'>
<tr>
<td width='13%' align='left' bgcolor='#C1DDF4'><p><strong>Service Type:</strong></p></td>
<td width='13%' align='left' bgcolor='#C1DDF4'><p><strong>Name:</strong></p></td>
<td width='13%' align='left' bgcolor='#C1DDF4'><p><strong>Phone:</strong></p></td>
<td width='13%' align='left' bgcolor='#C1DDF4'><p><strong>Email:</strong></p></td>
</tr>");
echo ("
<td align='left'><p><strong>Sales</strong></p></td>
<td align='left'><p>$query_row[SalesName]</p></td>
<td align='left'><p>$query_row[SalesPhone]</p></td>
<td align='left'><p><a href='mailto:$query_row[SalesEmail]'class='admin_links'>$query_row[SalesEmail]</p></a></td>
</tr>");
echo ("
<td align='left'><p><strong>Service</strong></p></td>
<td align='left'><p>$query_row[ServiceName]</p></td>
<td align='left'><p>$query_row[ServicePhone]</p></td>
<td align='left'><p><a href='mailto:$query_row[ServiceEmail]'class='admin_links'>$query_row[ServiceEmail]</p></a></td>
</tr>");
echo ("
<td align='left'><p><strong>Service Coordinator</strong></p></td>
<td align='left'><p>$query_row[ServiceCoorName]</p></td>
<td align='left'><p>$query_row[ServiceCoorPhone]</p></td>
<td align='left'><p><a href='mailto:$query_row[ServiceCoorEmail]'class='admin_links'>$query_row[ServiceCoorEmail]</p></a></td>
</tr>");
echo ("</table>");
}
}
}else{
echo 'No results found.';
}
}else{
echo 'Your search must be a 5-digit zip code.';
}
}
}
?>
</table>
This is the code for the Image map I need help with. I'd like to use the "CustClassID" data row for my value of lets say "23-LA".
<?php
$query = "SELECT * FROM search4 WHERE CustClassID = {$_GET['CustClassID']}";
echo ("<table width='600' border='0'>
<tr>
<td align='center'> <img src='images/greymap.png' border='0' usemap='#Map' />
<map name='Map' id='Map'>
<area shape='rect' coords='42,21,136,98' href='search6.php?CustClassID=23-LA' />
</map></td>
</tr>
</table>
");
?>
Basically, is there another way to get the same results as the search, by clicking on specific areas on the imagemap? Please point me in right direction.

Trying to pass a variable to another php page based on the data from checkbox

I'm trying to use php with mysql. basically i've an index page where user fills a form and another page where all rows are displayed. i've checkboxes for each row for deleting the selected row/rows. i'm trying to create a new page (namely details) where it shows only the selected row.
I'm trying to use $_GET but i could not do it. maybe the syntax is wrong. any help is welcome.
here are the relative code parts:
display.php:
<?
require_once('auth.php');?>
<html>
<head>
<title>Goruntule</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="checkboxForm">
<?
require "config.php"; // All database details will be included here
$page_name="display.php";
$start=$_GET['start']; // To take care global variable if OFF
if(!($start > 0)) { // This variable is set to zero for the first page
$start = 0;
}
$eu = ($start -0);
$limit = 10; // No of records to be shown per page.
$this1 = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
// WE have to find out the number of records in our table. We will use this to break the pages
$query2=" SELECT * FROM table1 ";
$result2=mysql_query($query2);
echo mysql_error();
$nume=mysql_num_rows($result2);
/////// The variable nume above will store the total number of records in the table////
/////////// Now let us print the table headers ////////////////
$bgcolor="#f1f1f1";
echo "<TABLE width=80% align=center cellpadding=5 cellspacing=0> <tr>";
echo "<td bgcolor='dfdfdf' > <font face='arial,verdana,helvetica' color='#000000' size='2'>#</font></td>";
echo "<td bgcolor='dfdfdf' > <font face='arial,verdana,helvetica' color='#000000' size='2'>ID</font></td>";
echo "<td bgcolor='dfdfdf' > <font face='arial,verdana,helvetica' color='#000000' size='2'>Time</font></td>";
echo "</tr>";
////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page///////////
$query=" SELECT * FROM table1 ORDER BY id DESC limit $eu, $limit ";
$result=mysql_query($query);
echo mysql_error();
//////////////// Now we will display the returned records in side the rows of the table/////////
while($rows = mysql_fetch_array($result))
{
if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
else{$bgcolor='#f1f1f1';}
echo "<tr>";
echo "<td><input name='checkbox[]' type='checkbox' value='" . $rows[id] . "'></td>";
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='1'>$rows[id]</font></td>";
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='1'>$rows[DateTime]</font></td>";
echo "<td>Details</td>";
//here is the problematic line i guess
echo "</tr>";
}
echo "</table>";
////////////////////////////// End of displaying the table with records ////////////////////////
///// Variables set for advance paging///////////
$p_limit=100; // This should be more than $limit and set to a value for whick links to be breaked
$p_f=$_GET['p_f']; // To take care global variable if OFF
if(!($p_f > 0)) { // This variable is set to zero for the first page
$p_f = 0;
}
$p_fwd=$p_f+$p_limit;
$p_back=$p_f-$p_limit;
//////////// End of variables for advance paging ///////////////
/////////////// Start the buttom links with Prev and next link with page numbers /////////////////
echo "<table align = 'center' width='50%'><tr><td align='left' width='20%'>";
if($p_f<>0){print "<a href='$page_name?start=$p_back&p_f=$p_back'><font face='Verdana' size='2'>PREV $p_limit</font></a>"; }
echo "</td><td align='left' width='10%'>";
//// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
if($back >=0 and ($back >=$p_f)) {
print "<a href='$page_name?start=$back&p_f=$p_f'><font face='Verdana' size='2'>PREV</font></a>";
}
//////////////// Let us display the page links at center. We will not display the current page as a link ///////////
echo "</td><td align=center width='30%'>";
for($i=$p_f;$i < $nume and $i<($p_f+$p_limit);$i=$i+$limit){
if($i <> $eu){
$i2=$i+$p_f;
echo " <a href='$page_name?start=$i&p_f=$p_f'><font face='Verdana' size='2'>$i</font></a> ";
}
else { echo "<font face='Verdana' size='4' color=red>$i</font>";} /// Current page is not displayed as link and given font color red
}
echo "</td><td align='right' width='10%'>";
///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
if($this1 < $nume and $this1 <($p_f+$p_limit)) {
print "<a href='$page_name?start=$next&p_f=$p_f'><font face='Verdana' size='2'>NEXT</font></a>";}
echo "</td><td align='right' width='20%'>";
if($p_fwd < $nume){
print "<a href='$page_name?start=$p_fwd&p_f=$p_fwd'><font face='Verdana' size='2'>NEXT $p_limit</font></a>";
}
echo "</td></tr></table>";
?>
<tr>
<td colspan="14" align="center" bgcolor="#FFFFFF">
<input name="delete" type="submit" id="delete" value="Delete">
<form>
<INPUT TYPE="BUTTON" VALUE="Previous" ONCLICK="window.location.href='http://......../util'">
</FORM></td>
</tr>
<?php
$checkbox=$_POST['checkbox'];
if($_REQUEST['delete']=='Delete'){
foreach($checkbox as $id => $value)
{$sql="DELETE FROM table1 WHERE id='$value'";
$result = mysql_query($sql);
}
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=display.php\">";
}
}
?>
details
<?
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
detail.php
<?php
require_once('auth.php');
$host="localhost";
$username="";
$password="";
$db_name="";
$tbl_name="table1";
mysql_connect("$host", "$username", "$password")or die("Cannot connect ". mysql_error());
mysql_select_db("$db_name")or die("Cannot select DB ". mysql_error());
$num=$_GET['var1'];
$query = "SELECT * FROM table1 where id='$num'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_row($result) or die(mysql_error());
?>
<table border="0" align="center" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="13" align="center" bgcolor="#FFFFFF"><strong>Bölge</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Time</strong></td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">
<input name="checkbox[]" type="checkbox" value="<? echo $rows['id']; ?>"></td>
<td bgcolor="#FFFFFF" align="center"><? echo $row['13']; ?></td>
<td bgcolor="#FFFFFF" align="center"><? echo $row['0']; ?></td>
</tr>
<tr>
<td colspan="14" align="center" bgcolor="#FFFFFF">
<input name="delete" type="submit" id="delete" value="Delete">
<form>
<input type=button value="Close" onClick="javascript:window.close();">
</form>
</tr>
<?php
$checkbox=$_POST['checkbox'];
if($_REQUEST['delete']=='Delete'){
foreach($checkbox as $key=>$value)
{$sql="DELETE FROM $tbl_name WHERE id='$value'";
$result = mysql_query($sql);
}
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=display.php\">";
}
}
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
<html><head><link href="loginmodule.css" rel="stylesheet" type="text/css" /></head></html>
As I've said, the only problem i'm guessing is with the syntax, or something small as i can echo the row when i gave the var1 a specific id.
I'm sorry if i'm reposting but i couldn't find an answer. Thanks!
Edit: I'm thinking of deleting checkbox parts and adding gif links in the while loop where users can delete, edit or detailed view of the corresponding row. seems easier i guess.
Make sure that the details link is within the while block.
<?php
while($rows = mysql_fetch_array($result)) {
echo 'Details';
}
?>
Looks like you should not be using double quotes.
<? echo "$rows[id]" ?>
Should be
<?php echo $rows[id]; ?>
I also suggest you use 'id' as the name of the get rather than 'var1'. 'var1' does not mean anything whereas 'id' makes more sense.
Details
It's because you are using $rows outside your while-loop. You have to put the
Details
inside the while loop.
//EDIT:
Alright, I've stripped your code to the very neccessary according to your problem. So don't just copy/paste the code, it probably won't work. But read it carefully, and I hope you get the idea and see what may be wrong with your code ;)
display.php
<?php
require_once('auth.php');
require "config.php";
$page_name="display.php";
$start = (isset($_GET['start']) && $_GET['start'] < 1) ? 0 : $_GET['start'];
$eu = ($start-0);
$limit = 10;
$query="SELECT * FROM table1 ORDER BY id DESC limit $eu, $limit";
$result=mysql_query($query);
echo mysql_error();
$i = 0; //counter for the bg-color
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="checkboxForm">
<table width="80%" align="center" cellpadding="5" cellspacing="0">
<?php while($rows = mysql_fetch_array($result)) :
$bgcolor = $i%2 == 0 ? '#ffffff' : '#f1f1f1';
?>
<tr>
<td>
<input name="checkbox[]" type="checkbox" value="<?php echo $rows['id']; ?>">
</td>
<td style="align: left; font-family: Verdana; font-size: 10px; background-color: <?php echo $bgcolor; ?>;" id="title">
<?php echo $rows['id']; ?>
</td>
<td style="align: left; font-family: Verdana; font-size: 10px; background-color: <?php echo $bgcolor; ?>;" id="date">
<?php echo $rows['DateTime']; ?>
</td>";
<td>
Details
</td>
</tr>
<?php endwhile; ?>
</table>
</form>
detail.php
<?php
require_once('auth.php');
$num= isset($_GET['var1']) ? $_GET['var1'] : '';
$query = "SELECT * FROM table1 where id='$num'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
?>
<form name="form1" method="post" action="">
<table border="0" align="center" cellspacing="1" cellpadding="0">
<input name="checkbox[]" type="checkbox" value="<? echo $rows['id']; ?>">
<? echo $row['13']; ?>
<? echo $row['0']; ?>
<input name="delete" type="submit" id="delete" value="Delete">
<button onClick="javascript:window.close();">Close</button>
</table>
</form>
And not only for security's sake, you should get more familiar with PHP and some design patterns before publishing your website.

member control through admin account using php

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:
<?php
require_once('auth.php');
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");
}
?>
<html>
<head>
<meta name="author" content="Kai Oswald Seidler">
<link href="../loginmodule.css" rel="stylesheet" type="text/css">
<title></title>
</head>
<body>
<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']." </td>";
echo "<td class='tabval'>".$row['member_id']." </td>";
echo "<td class='tabval'><a onclick=\"return confirm('".$TEXT['userlist-sure']."');\" href='userlist.php?action=del&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>
</html>
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.
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 &member_1d in the href with a real & and a real i as &member_id.
$TEXT is an array contaning all the language strings for the selected language.
You find the strings defined unter /lang/yourlanguage.php
In 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 &member_1d with &member_id
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 database
while($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 . ' - ' delete '</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.

Categories