am_25 Posted February 8, 2007 Share Posted February 8, 2007 Hi, I'm trying to pass the values of a List box with multiple selection to another php file. When I try to access that varible in the other file, the array is returning 0 value. First file empquery.php <tr><td> <form action='empresult.php' method='post'> <br>Designation: <?php $sql2="SELECT distinct(designation) from empdet order by designation asc "; $result2=mysql_query($sql2);?> <SELECT multiple="multiple" name="desi[]"> <?php While ($row=mysql_fetch_assoc($result2)) { $desi=$row['designation']; echo "<OPTION value='$desi'>$desi</OPTION> "; } ?></select>   <input type='submit' name='submit4' value='submit'></form> </form></td></tr> In the empresult.php, i retrieve the value of the list box, but it gives 0 as the array value elseif(isset($_POST['submit4'])) { $designation=$_POST['designation']; $n=count($designation); $sql="SELECT * from empdet where empid = '$empid'"; $result=mysql_query($sql); echo $n; echo "Test"; } I tried an example and it works, please see working code below <?php if (isset($_POST['submit'])) { $test=$_POST['test']; $n=count($test); echo 'You selected ',$n ,'<br />'; if ($test){ foreach ($test as $t){echo 'You selected ',$t,'<br />';} } } ?> <html> <body> <form action="multiple.php" method="post"> <select name="test[]" multiple="multiple"> <option value="one">one</option> <option value="two">two</option> <option value="three">three</option> <option value="four">four</option> <option value="five">five</option> </select> <input type="submit" name="submit" value="Send" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/37595-value-not-passed-in-the-array/ Share on other sites More sharing options...
steveclondon Posted February 8, 2007 Share Posted February 8, 2007 shouldn't you select name on the first be designation Quote Link to comment https://forums.phpfreaks.com/topic/37595-value-not-passed-in-the-array/#findComment-179859 Share on other sites More sharing options...
am_25 Posted February 9, 2007 Author Share Posted February 9, 2007 Yea I made a mistake, I changed it and even then it does not work. I think it is due to the dynamic generation of the list box, it is not getting stored in the array, when submit is clicked. Quote Link to comment https://forums.phpfreaks.com/topic/37595-value-not-passed-in-the-array/#findComment-180430 Share on other sites More sharing options...
Jessica Posted February 9, 2007 Share Posted February 9, 2007 echo 'You selected ',$n ,'<br />'; You need . not , Quote Link to comment https://forums.phpfreaks.com/topic/37595-value-not-passed-in-the-array/#findComment-180447 Share on other sites More sharing options...
am_25 Posted February 9, 2007 Author Share Posted February 9, 2007 I tried it but still it gives value as 0. The Values are not getting passed to the Array varibale in the select. When I give static values for the list box no problem it works. But when the list box is generated by the DB values, then no values are passed. I did this simple script so as to debug <?php include "connect.php"; if (isset($_POST['submit'])) { $test=$_POST["test"]; $n=count($test); echo "You selected ".$n." value. <br />"; if ($test){ foreach ($test as $t){echo 'You selected ',$t,'<br />';} } } ?> <html> <body> <form action="multiple.php" method="post"> <?php $sql2="SELECT distinct(designation) from empdet order by designation asc "; $result2=mysql_query($sql2);?> <SELECT multiple="multiple" name="test[]"> <?php While ($row=mysql_fetch_assoc($result2)) { $desi=$row['designation']; echo "<OPTION value='$desi'>$desi</OPTION> "; } ?></select>   <input type='submit' name='submit' value='submit'></form> </form></td></tr> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/37595-value-not-passed-in-the-array/#findComment-180453 Share on other sites More sharing options...
kenrbnsn Posted February 9, 2007 Share Posted February 9, 2007 At the top of the empresult.php script put the following line: <?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?> This will dump to the screen the values that are being sent from your form. This may help you find your problem. Ken Quote Link to comment https://forums.phpfreaks.com/topic/37595-value-not-passed-in-the-array/#findComment-180454 Share on other sites More sharing options...
am_25 Posted February 9, 2007 Author Share Posted February 9, 2007 The Array varible desi is empty this is the value Array ( [desi1] => [submit4] => submit ) What do I do? Quote Link to comment https://forums.phpfreaks.com/topic/37595-value-not-passed-in-the-array/#findComment-180461 Share on other sites More sharing options...
kenrbnsn Posted February 9, 2007 Share Posted February 9, 2007 There's something wrong somewhere. There is no form element named "desi1" in the code you posted. Please do a "show source" once the form is displayed and post the generated code. Ken Quote Link to comment https://forums.phpfreaks.com/topic/37595-value-not-passed-in-the-array/#findComment-180470 Share on other sites More sharing options...
am_25 Posted February 9, 2007 Author Share Posted February 9, 2007 This is the search form view source code <tr><td> <form action='empresult.php' method='post'> <br>Designation: <SELECT multiple="multiple" name="desi1[]"> <OPTION value='Manger'>Manger</OPTION> <OPTION value='Mgr'>Mgr</OPTION> <OPTION value='QA'>QA</OPTION> <OPTION value='SE'>SE</OPTION> <OPTION value='SSE'>SSE</OPTION> </select>   <input type='submit' name='submit4' value='submit'></form> </form></td></tr> This is for the result page. <pre>Array ( [desi1] => [submit4] => submit ) </pre><link rel='stylesheet' href='style.css' type='text/css'><img src='Thi_logo.jpg' alt='Thales Software India'><br><br><p align = 'center'> Employee Details </p><table align = 'center' border=1px><tr align = 'center' class='headline'>Employee Search Results</tr><tr ><td><b>Employee Id</b></td><td><b>Employee Name</b></td><td><b>Date of Joining</b></td><td><b>Designation</b></td><td><b>Grade</b></td><td><b>CTC</b></td></tr>0Test</table><br><br><br><table align = 'center'><tr><td></td><td><a href='employee.php'>Home</a> | </td> <td><a href='empdet.php'>Enter Employee details</a> | </td> <td><a href='empquery.php'>Search Employee details</a> | </td> <td><a href='logout.php'>Logout</a></td><td></td></tr></table> Quote Link to comment https://forums.phpfreaks.com/topic/37595-value-not-passed-in-the-array/#findComment-180478 Share on other sites More sharing options...
Jessica Posted February 9, 2007 Share Posted February 9, 2007 Well there you go, it's called desil, not test... Are you actually selecting any? Quote Link to comment https://forums.phpfreaks.com/topic/37595-value-not-passed-in-the-array/#findComment-180485 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.