Forum Moderators: coopster

Message Too Old, No Replies

Opinion on this code to approve users please

Any suggestions to improve it are welcome

         

travelbuff

11:18 pm on Dec 23, 2003 (gmt 0)

10+ Year Member



I am learning PHP so I thought I would ask for feedback on the work I am doing. This code has 2 purposes: 1. to show users that have registered but have not been approved (approved = 0) and 2. approve the user and reload the remaining unapproved users. Comments on my methodology, efficiency of code, documentation or anything else are appreciated.


//approve any users before reloading the page
if ($user_id && $approve) {
$approval_query = "UPDATE users SET approved=1 WHERE user_id = '$user_id'";
$approval_result = @mysql_query($approval_query) OR DIE ('could not update: ' . mysql_error() );
}
//select unapproved rows from the users table
$users_select = 'SELECT * FROM users WHERE approved = 0' ;
$users_result = @mysql_query($users_select) or die(mysql_error()) ;
$approve = '<a href="{approve.php?user_id=$user_id&approve=yes">approve</a>';
if (mysql_num_rows($users_result) >0) {
//give the fields names
while ($users_row = mysql_fetch_array($users_result)) {
$user_id = $users_row['user_id'] ;
$user_name = $users_row['user_name'] ;
$admin_email = $users_row['admin_email'] ;
$contact_name = $users_row['contact_name'];
$inq_email_1 = $users_row['inq_email_1'];
$inq_email_2 = $users_row['inq_email_2'];
$phone_num = $users_row['phone_num'];
$fax_num = $users_row['fax_num'];
$street_addr = $users_row['street_addr'];
$city = $users_row['city'];
$state = $users_row['state'];
$zip = $users_row['zip'];
$country = $users_row['country'];
$date_registered = $users_row['date_registered'];
$approve = '<a href="approve.php?user_id='.$user_id.'&approve=1">approve</a>';
//build the display block
$display_users .= <<<diplayusers
<tr>
<td>$user_id</td>
<td>$user_name</td>
<td>$admin_email</td>
<td>$contact_name</td>
<td>$inq_email_1</td>
<td>$inq_email_2</td>
<td>$phone_num</td>
<td>$fax_num</td>
<td> $street_addr, $city, $state, $zip, $country </td>
<td>$date_registered</td>
<td>$approve</td>
</tr>
diplayusers;
} // close the while loop
} else {
$display_users = "There are no users to approve." ;
} // close the else statement
?>
<h3>Users awaiting approval:</h3>
<table width="95%" border="1">
<tr>
<td width="4%"><strong>User ID</strong></td>
<td width="15%"><strong>User Name</strong></td>
<td width="8%"><strong>Admin Email</strong></td>
<td width="8%"><strong>Contact Name</strong></td>
<td width="8%"><strong>Inquiry Email 1</strong></td>
<td width="8%"><strong>Inquiry Email 2</strong></td>
<td width="8%"><strong>Phone</strong></td>
<td width="8%"><strong>Fax</strong></td>
<td width="18%"><strong>Address</strong></td>
<td width="7%"><strong>Date Registered</strong></td>
<td width="7%"><strong>Approve</strong></td>
</tr>
<? echo "$display_users";?>
</table>

bcolflesh

12:25 am on Dec 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hopefully this page is in a protected area, as anyone could inject a userid and make themselves approved or disappove someone else:

<a href="approve.php?user_id='.$user_id.'&approve=1">approve</a>

travelbuff

12:53 am on Dec 24, 2003 (gmt 0)

10+ Year Member



yes, it is in an admin area that has .htaccess protection.