leoric80 Posted June 27, 2013 Share Posted June 27, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/279627-confused-about-_post-and-arrays/ Share on other sites More sharing options...
boompa Posted June 27, 2013 Share Posted June 27, 2013 Time for you to spend some time learning about arrays, I guess. Quote Link to comment https://forums.phpfreaks.com/topic/279627-confused-about-_post-and-arrays/#findComment-1438173 Share on other sites More sharing options...
ginerjm Posted June 27, 2013 Share Posted June 27, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/279627-confused-about-_post-and-arrays/#findComment-1438179 Share on other sites More sharing options...
leoric80 Posted June 27, 2013 Author Share Posted June 27, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/279627-confused-about-_post-and-arrays/#findComment-1438196 Share on other sites More sharing options...
ginerjm Posted June 27, 2013 Share Posted June 27, 2013 By removing the value= from your checkbox tag you will never get a response from $_POST['selected']; Please re-read my first post on what you have to do or simply remove the checkboxes entirely. Quote Link to comment https://forums.phpfreaks.com/topic/279627-confused-about-_post-and-arrays/#findComment-1438198 Share on other sites More sharing options...
leoric80 Posted June 27, 2013 Author Share Posted June 27, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/279627-confused-about-_post-and-arrays/#findComment-1438204 Share on other sites More sharing options...
leoric80 Posted June 27, 2013 Author Share Posted June 27, 2013 I thought I would try a loop to get the data out like following but that doesn't seem to help either foreach($_POST['selected'] as $value) { print $value['first_name']; } Quote Link to comment https://forums.phpfreaks.com/topic/279627-confused-about-_post-and-arrays/#findComment-1438208 Share on other sites More sharing options...
AbraCadaver Posted June 27, 2013 Share Posted June 27, 2013 foreach($_POST['selected'] as $value) { print $value; } Quote Link to comment https://forums.phpfreaks.com/topic/279627-confused-about-_post-and-arrays/#findComment-1438210 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.