-1

I'm trying to create an admin page where the admin must approve a user registration before the user logs in.I'm trying to show in this page all the users which have been registered but still waiting for admin approval for log in.So I want to create a button close to each unconfirmed user with the value"Yes" to give the admin the possibility to approve his account.If "Yes" button is set by the admin the user should be approved so the approval field which is stored in my database should be updated to 1.This is the idea.When executing the code the buttons are displayed but no update is made for the field approval!

Also the buttons are displayed but are not functional.Can someone help me to make the "Yes" buttons functional? This is my code:

<html >
<head>
<title></title>
</head>

<body>
<?php
if( !($database=mysql_connect("localhost","root",""))||!(mysql_select_db("st_login",$database))  )
   print("Could not connect");
if(isset($_POST['yes'])){

     $id = intval($_POST['id']);
$update_query= "UPDATE login SET `approval`=1 WHERE `id` = '".$id."'";
mysql_query($update_query,$database);
 }

$query = "SELECT * FROM `login` WHERE `admin` =0";
 if(!($result=mysql_query($query,$database)))
{
    print("Could not execute query");
    die (mysql_error());//ose error
} else
  while($query_row=mysql_fetch_assoc($result))
  {

 $firstname=$query_row['firstname'];
$lastname=$query_row['lastname'];
$username=$query_row['username'];
$password=$query_row['password'];
$email=$query_row['email'];
$cv=$query_row['cv'];
$id=$query_row['id'];

if($query_row['approval']==0){
  echo "this user is waiting for you approval";
echo $firstname.'   '.$lastname.'  has this cv:'.$cv.'<br />
Do you want to approve his account?
<form action="admin.php" method="post">
<input  type="text" style="display: none;" value="$id" name="id">
<input  type="submit" value="yes" name="yes">
</form>
<br/>';
}
}
mysql_close($database);
?>
</body>
</html>

Anyone helping me with this updating?Thanks in advance!

John Dow
  • 47
  • 2
  • 7

2 Answers2

0

Change the button to be

<form action="admin.php" method="post"><input type="submit" value="'.$id.'" name="id"></form><br />';

So that the whole echo will be

echo $firstname.' '.$lastname.' has this cv:'.$cv.'<br /> Do you want to approve his account? <form action="admin.php" method="post"><input type="submit" value="'.$id.'" name="id"></form><br />';

The name of the form element is what you should expect to be the key in the $_POST array, and the value is what you should expect to be the value of $_POST['id']

Also, you should use $_POST not $_GET as you have specified the form method to be post

Mahmoud Tantawy
  • 713
  • 5
  • 12
0

You should change the last part of your code. Your form method is POST and yet you're trying to get id via GET. You can't do that, and you can't get the id from the input like this.

This is what you should do:

if($query_row['approval']==0){
  echo "this user is waiting for you approval";
echo $firstname.'   '.$lastname.'  has this cv:'.$cv.'<br />
Do you want to approve his account?
<form action="admin.php" method="post">
<input  type="hidden" value="$id" name="id">
<input  type="submit" value="yes" name="yes">
</form>
<br/>';
}

}
mysql_close($database);
?>

And on the line

$id = intval($_GET['id']);

It should turn into

 $id = intval($_POST['id']);
Mahmoud Tantawy
  • 713
  • 5
  • 12
Phiter
  • 14,570
  • 14
  • 50
  • 84