Jump to content

Value not passed in the Array


am_25

Recommended Posts

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>
&nbsp
<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>

Link to comment
Share on other sites

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>
&nbsp
<input type='submit' name='submit' value='submit'></form>
</form></td></tr>
</body>
</html>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>
&nbsp
<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>

 

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.