check boxes and php!! :O

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

php-punk
New php-forum User
New php-forum User
Posts: 60
Joined: Sun Feb 02, 2003 2:10 am
Location: Leeds, Uk
Contact:

check boxes and php!! :O

Postby php-punk » Mon Feb 24, 2003 3:38 am

can somebody give me some idea on how i would create the code for a admins settings page for a guest book, were when logged in, the admin is abe to select certain posts and delete?!

any help on check boxes and PHP would be gratly appreciated!!

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Mon Feb 24, 2003 5:03 am

if(isset($checkbox['$i']))
{
//Delete query
}

User avatar
xlordt
New php-forum User
New php-forum User
Posts: 34
Joined: Thu Dec 12, 2002 9:00 pm
Location: NJ
Contact:

Postby xlordt » Mon Feb 24, 2003 5:55 am

if($delete == '1'){
//delete from db
}else{
//what ever
}

<INPUT TYPE=\"checkbox\" NAME=\"delete\" VALUE=\"1\">

php-punk
New php-forum User
New php-forum User
Posts: 60
Joined: Sun Feb 02, 2003 2:10 am
Location: Leeds, Uk
Contact:

Postby php-punk » Mon Feb 24, 2003 6:04 am

thx pejone, but how would i apply that with multiple check boxes?

and how would i display it using the variables?|

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Mon Feb 24, 2003 6:12 am

whan you will generate admin page

while($query=mysql_fetch_array($query))
{
echo "<input type=chackbox value=array[$data[id]]">;
}

php-punk
New php-forum User
New php-forum User
Posts: 60
Joined: Sun Feb 02, 2003 2:10 am
Location: Leeds, Uk
Contact:

Postby php-punk » Mon Feb 24, 2003 8:05 am

ahh i think i get it now.. but how wud i removed only the checked values?

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Mon Feb 24, 2003 8:10 am

they are put into the array if and only if they are checked

php-punk
New php-forum User
New php-forum User
Posts: 60
Joined: Sun Feb 02, 2003 2:10 am
Location: Leeds, Uk
Contact:

Postby php-punk » Mon Feb 24, 2003 8:50 am

well i still dont get it, i'll look around for a script tha uses check boxes and learn from it, but thx n e way!!

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Mon Feb 24, 2003 9:36 am

Code: Select all

<?php
if(isset($_POST['submit']))
{
  $size = sizeof($_POST['form_checkbox']);
  for($x=0; $x<$size); $x++)
  {
    echo $_POST['form_checkbox'][$x].'<br>';
  }
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="checkbox" name="form_checkbox[]" value="one"><br>
<input type="checkbox" name="form_checkbox[]" value="two"><br>
<input type="checkbox" name="form_checkbox[]" value="three"><br>
<input type="checkbox" name="form_checkbox[]" value="four"><br>
<input type="submit" name="submit" value="submit">

</form>


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot], Google Feedfetcher and 3 guests