Skip to content
WJunction - Webmaster Forum

PHP Approval/Deny help

Status
Not open for further replies.

Jayar

Experienced Member
629
2009
15
Hey erybody! I'm making a CMS and right now I'm working on the avatars.
When they upload their avatars, it automatically sets their approved status to false, because i want to be able to approve/deny them in the acp.
This is what I have for the Approve/deny portion, since i already got the uploading script all taken care of.

PHP:
$picture = mysql_query("SELECT * FROM images WHERE approved='false'");
echo "<form action='approve.php?do=submit' method='post'>"
while($result = mysql_fetch_array($picture)){
echo "<img src='../".$result['path']."'>";
echo "<input type='checkbox' id='".$result['id']."' />
}
echo "</form>";

Approve.php?do=submit :
PHP:
$do = $_GET['do'];
//this says whats going to be in approve.php?do=submit
if($do == submit){
//code here
}

I've been stuck on this for a few hours trying to figure and google a way on how to get more than one $_POST thingies and update them in the mysql.
Im not sure if thats a good description of my problem or not lol
 

7 comments

something like this? i wrote this for streamscene.me :)

PHP:
    if (isset($_GET['do']) && isset($_POST['id']) && is_array($_POST['id']))
    {
        foreach ($_POST['id'] as $id)
        {
            if (!mysql_query("UPDATE movies SET top=1 WHERE id = '$id'"))
            {
                echo error_message(sql_error());
            }
        }
    }
 
So,

PHP:
$do = $_GET['do']; 
//this says whats going to be in approve.php?do=submit 
if($do == submit){ 
 if (isset($_GET['do']) && isset($_POST['id']) && is_array($_POST['id'])) 
    { 
        foreach ($_POST['id'] as $id) 
        {
            if (!mysql_query("UPDATE images SET approve=true WHERE id = '$id'")) 
            { 
                echo error_message(sql_error()); 
            } 
        } 
    }  
}

ill try it:)
 
I don't really get what you're trying to do?
From what I can see, isn't essentially just you manually approving avatars? So you initially have the avatar approved='false' and you want it on submit to make approved='true'?
I don't get what you mean by 'multiple post thingies'
 
Notice I changed your checkbox.
I added name=" and value=""

I'm fairly tired atm and can't focus. So could be entirely wrong :|

PHP:
<?php
if($_GET['do'] == 'submit' && !empty($_POST['id'])){
  foreach($_POST['id'] as $ID){
    if(!is_numeric($ID)){
      echo ' Whaaaat, the ID '.$ID.' isn\'t a number? ';
      exit;
   }
   mysql_query('UPDATE `images` SET `approved` = "true" WHERE `id` = '.$ID);
  }
}else{
  // Show form
  $picture = mysql_query("SELECT path, id FROM images WHERE approved='false'"); 
  echo "<form action='approve.php?do=submit' method='post'>" ;
  while($result = mysql_fetch_array($picture)){ 
   echo "<img src='../".$result['path']."'>"; 
   echo '<input type="checkbox" name="id[]" value="'.$result['id'].'" id="'.$result['id'].'" />';
  } 
  echo "</form>";
}
?>
 
what your going to want to do is a switch statement heres a the base structure from a login i had minus the code between as an example.

PHP:
<?php
if (isset ( $_GET ['do'] )) {
	switch ($_GET ['do']) {
		
		case 'logout' :
		//code for ?do=logout
		break;
			
		case 'view' :
	   //code for ?do=view
	   break;
		
		case 'register' :
        //code for ?do=register
        break;
        
		default :
		die ( 'Invalid Command' );
		break;
	}
 }
?>


That will allow you to do page.php?do=submit and it will execute whatever code in in the submit code area.
 
Notice I changed your checkbox.
I added name=" and value=""

I'm fairly tired atm and can't focus. So could be entirely wrong :|

PHP:
<?php
if($_GET['do'] == 'submit' && !empty($_POST['id'])){
  foreach($_POST['id'] as $ID){
    if(!is_numeric($ID)){
      echo ' Whaaaat, the ID '.$ID.' isn\'t a number? ';
      exit;
   }
   mysql_query('UPDATE `images` SET `approved` = "true" WHERE `id` = '.$ID);
  }
}else{
  // Show form
  $picture = mysql_query("SELECT path, id FROM images WHERE approved='false'"); 
  echo "<form action='approve.php?do=submit' method='post'>" ;
  while($result = mysql_fetch_array($picture)){ 
   echo "<img src='../".$result['path']."'>"; 
   echo '<input type="checkbox" name="id[]" value="'.$result['id'].'" id="'.$result['id'].'" />';
  } 
  echo "</form>";
}
?>

Worked perfect thanks:D
 
Status
Not open for further replies.

About the author

J
Experienced Member · Joined
Life sucks. Then you die. web design, movies, friends, music.
629
Messages
15
Reactions
18
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom