FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


array check box on php script using $_POST





Philip
I am looping check box using this on my php script..

Code:
   while($row=mysql_fetch_array($query))
   {
   $i++;
   echo '
       <tr>
         <td><input type="checkbox" name="Discard['.$i.']" ></td>       
       </tr>';
   }   


when i am try to access Discard using $_POST i get empty variable.. -.-"
like this

Code:
echo "Hasil = ".$_POST["Discard[1]"];


or like this

Code:

$i=1;
echo "Hasil = ".$_POST["Discard[".$i."]"];


but i get the variable when used this, but it seem no security.

Code:

$i=1;
echo "Hasil = ".$Discard[1];



what should i do ? thanks for all kind of help...
LukeakaDanish
Maybe im being stupid...but isnt your checkbox named "Discard" and the array you are trying to call your value from "Terima"

That seems wrong Confused

Also, you havent defined the variable $i, but im assuming thats outside the code you coppied to the forum
Philip
ah, sorry Embarassed
please help me once again.
LukeakaDanish
Try this:

Code:

$name = $_POST["Discard"];

echo ("Hasil = ".$name[1]); //ive put the echo statement inside a set of parenthis to make it easier to read...
Philip
LukeakaDanish wrote:
Try this:

Code:

$name = $_POST["Discard"];

echo ("Hasil = ".$name[1]); //ive put the echo statement inside a set of parenthis to make it easier to read...


thanks,, but i was already get another clue
like this

Code:
$i=1;
echo "Hasil = ".$_POST["Discard"][$i];


any way thanks v much Smile
DSitC
Yep.

If you use [] inside the name of a form element, it generates an associative Array from the name.

Example:
Code:
<input type="text" name="user[name][first]" value="Flurps" />

...should generate...
Code:
$_POST['user']['name']['first'] == 'Flurps';


BTW: You need to utilize this effect if you want to use a select box with the multiple select option turned on:
Code:
<select name="user['options'][]">
  <option value="a">Option 1</option>
  <option value="b">Option 2</option>
  <option value="c">Option 3</option>
  <option value="d">Option 4</option>
</select>

...this would result in the following...
Code:
$_POST['user']['options'] == array(
  0 => 'a',
  1 => 'b',
  2 => 'c',
  3 => 'd'
);

if all Options have been selected.
Philip
thanks for selection box techinique Wink
Related topics
check box validation
error in my PHP script
Inserting data to MYSQL with a PHP script
Simple PHP script not working
Preventing bad PHP script calls
php script not loading
Need php script 50 frih$ if you do
creating forms using SQL?
How do i execute an sql file in a php script?
Connected to another part of a php script.
know how much memory are your php scripts using
vBulletin Config.php script
Uploading an Image using PHP script - RESOLVED
How do you Create a New Database using a php script?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.