FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » test if $_POST variable is set
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: test if $_POST variable is set [message #175834 is a reply to message #175831] Sat, 29 October 2011 13:09 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
On Fri, 28 Oct 2011 22:40:31 -0700, cerr wrote:

> I have a form with various checkboxes, they got names i have from a db
> to identify them.
> Now I would like to check what has been posted by the form. For that I
> would like to read all the field names from the db and check if they
> have been set something like this:
>
> $result = mysql_query("SELECT * FROM specialty"); while($row =
> mysql_fetch_array($result)) {
> if (isset($_POST[$row['name']])) {
> var_dump($POST);
> session_unset();
> }
>
> But this doesn't seem to work the way I expected it to? I.e. I would
> liek to check if $_POST['MyCheckbox'] is set now but MyCheckbox is a
> name from the database. How do I do this best, the easiest way?

A checkbox name element is only defined (set) in the $_POST array if it
is checked when the form is submitted. The value of the element will be
"on" unless a value is defined for the form element, in which case that
value will be used.

So if you want an unchecked box to have a value in $_POST, you have to
give it one yourself:

<?php
print_r($_POST);
// set values in $_POST for checkboxes
// if checked, set $_POST[checkbox] = true
// if not checked, set $_POST[checkbox] = false
$result = mysql_query("SELECT * FROM specialty");

while($row = mysql_fetch_array($result)) if (!isset($_POST[$row
['name']])) $_POST[$row['name']] = 0;

print_r($_POST);
?>

Rgds

Denis McMahon
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: `********AMAZING HOT PHOTOS & VIDEOS ********
Next Topic: Suche Buch zur OOA/OOD
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Dec 01 20:49:44 GMT 2024

Total time taken to generate the page: 0.03994 seconds