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
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>';
}

Link to comment
Share on other sites

#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>';

}

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.