Jump to content

Confused about $_post and arrays


leoric80

Recommended Posts

Hey, I am having difficulty viewing the data submitted by my web form, I would hugely appreciate any help with this. I am probably going about this the wrong way but hey.

 

My code for main.php


                        <form action="outbox.php" method="post"name="sendform">
                        <input type="hidden" value="07500000000" name="senderno">
                        <input type="hidden" value="<?php echo $school_id ?>" name="school_id">
                        <span align="left" class="label fix">To:</span><br>
                        <input placeholder="Search name" id="searchInput" type="text" name="destno" autocomplete='off'><br>

<p><button type=button class="btn1">Hide</button><button type=button class="btn2">Show</button></p>
<boobies>
<script src="table.js"></script>

<script language="JavaScript">
function toggle(source) {
  checkboxes = document.getElementsByName('selected[]');
  for(var i=0, n=checkboxes.length;i<n;i++) {
    checkboxes[i].checked = source.checked;
  }
}

</script>


<?php



# display returned data
if (mysql_num_rows($result) > 0)
{
    ?>
    <table style="border: 0px solid black cellpadding="5"">
        <tr><td><input type="checkbox" onClick="toggle(this)" /> </td></tr>
        <?php
            while ($row = mysql_fetch_assoc($result))
            {


                echo '<tr><td>';
                echo '<input type="checkbox" name="selected[]" value=""/>';
                echo '</td>';
                    echo '<td>'.$row['first_name'].'</td>';
 echo '<td>'.$row['last_name'].'</td>';
                echo '<td>'.$row['year'].'</td>';
                echo '<td>'.$row['class'].'</td>';
                echo '<td>'.$row['p1_first_name'].' '.$row['p1_family_name'].'</td>';
                 echo '<td>'.$row['p1contact_no'].'</td>';
echo '</tr>';

            }

        ?>
    </table>
    <?php
}
else
    echo '<p>No data</p>';


?>

outbox.php

  echo "<pre>";
        print_r($_POST);
        echo "</pre>";

$_POST Output from outbox.php 

Array
(
    [senderno] => 07500000000
    [school_id] => 1
    [destno] => 
    [selected] => Array
        (
            [0] => 
        )

    [message] => dwqd
)

The issue is I would like to be able to display the 'selected' items in outbox.php, the other variables are being displayed however I do not know how to get that array to display their values also, does that make any sense?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/279627-confused-about-_post-and-arrays/
Share on other sites

Or perhaps more pertinently - do a google on php and checkboxes.

 

You don't assign a value to your checkbox when you process the query results to generate it.  The value= that you output will then be returned as the value of $_POST['selected'].  Note that each record you process and output needs a unique value assigned to it. I don't know what that would be in your case.

Hey

 

Thanks guys. I have removed the value option from my checkbox and read up a little on arrays, would I be correct in saying that this is a multi-dimensional array in this particular instance? Think I need some coffee...

 

Sorry I know I am being slow today, im VERY new to coding and this one seems to be busting my head open!

 

Cheers 

Hi Thanks for your help, i am with you I think :) 

 

 echo '<input type="checkbox" name="selected[] vaule="'.$row['student_id_internal'].'"/>';

 

This is what I have gone with, this is unique value from the query so should do the job, it still shows the following when I echo the $_POST..

Array
(
    [senderno] => 07500000000
    [school_id] => 1
    [destno] => 
    [selected] => Array
        (
            [0] => on
            [1] => on
        )

    [message] => rgreg
)

I assume that is because this is an array inside of an array($_POST), is my understanding of that correct?

 

Thanks again

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.