Jump to content

echoing wrong information


chard

Recommended Posts

Hi me again  ;D

 

Not sure what I'm doing wrong here but what's meant to happen is:

if a $_POST isset do this {

OK that works

 

but what happens is when i do the echo

foreach( $value as $to => $number){
        echo $number . '<br>';
}

 

It echos as if every $_POST is set.

Maybe I'm checking if post is set incorrectly?

 

Any help would be appreciated.

 

<?php

foreach ($_POST as $set => $confirm)
{
if (isset($confirm)) {

$_POST['name1'] = '01';
$_POST['name2'] = '02';
$_POST['name3'] = '03';
$_POST['name4'] = '04';
$_POST['name5'] = '05';

foreach($_POST as $key => $value[])
  {
        $$key = $value;

  }

foreach( $value as $to => $number){
        echo $number . '<br>';
}
                        }
}
?>

<form name="frmsms" value="sms.php" method="POST">
<label>name1
<input type="checkbox" name="name1" value="name1"></label><br>
<label>name2
<input type="checkbox" name="name2" value="name2"></label><br>
<label>name3
<input type="checkbox" name="name3"></label><br>
<label>name4
<input type="checkbox" name="name4"></label><br>
<label>Frank
<input type="checkbox" name="name5"></label><br>
<input type="submit" value="submit">
</form>

Link to comment
https://forums.phpfreaks.com/topic/71231-echoing-wrong-information/
Share on other sites

can u tell us what your code does here:

 

foreach ($_POST as $set => $confirm)
{
if (isset($confirm)) {

$_POST['name1'] = '01';
$_POST['name2'] = '02';
$_POST['name3'] = '03';
$_POST['name4'] = '04';
$_POST['name5'] = '05';

 

and here:

 

foreach($_POST as $key => $value[])
  {
        $$key = $value;

  }

 

 

and here:

 

foreach( $value as $to => $number){
        echo $number . '<br>';
}

#1

 

Put the values of every $_POST into $confirm and if $confirm is set assign values to posts whether they exist.

 

#2

 

For every $_POST put the name into $value and create a variable that corresponds to the $_POST's name

 

#3

Seems very pointless as i look at it now possibly better solution?

for ($i = 1; $i <6; $i++) {

echo $value[$i] . '<br>';

}

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.