Jump to content

Unable to post results of selected droplist item using database ....


robinhood

Recommended Posts

Can any 1 help me on my mistakes.I suppose i had declare the :".$_POST['drop1']; wrongly .i am trying to display the selected items form the drop list using post method but it failed. 

 

//populating rank/name from admin table to drop down list

$query="SELECT name FROM admin where timecounter='1'";

 

/*order by clause to the sql statement if the names are to be displayed in alphabetical order */

 

$result = mysql_query ($query);

echo "<select name='drop1'Select Name>";

   

// printing the list box select command

 

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt

echo "<option value=$nt[id]>$nt[name]</option>";

 

/* Option values are added by looping through the array */

}

echo "</select>";// Closing of list box

?>

  </p>

  <p>

    <input type="submit" name="Submit" value="Submit" >

 

  </p>

</form>

</body>

<?php echo "Name is:".$_POST['drop1']; ?>

<p></p>

<p></p>

<?php echo "Product Description:".$_POST['jobdescription']; ?>

</html>

Something like:

 

<?php
$query="SELECT name FROM admin where timecounter='1'";
/*order by clause to the sql statement if the names are to be displayed in alphabetical order */
$result = mysql_query ($query) or die(mysql_error());
echo "<select name='drop1'";
     
// printing the list box select command

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo '<option value='.$nt['id'].'>'.$nt['name'].'</option>';

/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box 
?>
  </p>
  <p>
    <input type="submit" name="Submit" value="Submit" >
   
  </p>
</form>
<?php
if(isset($POST('Submit'))){
echo 'Name is: '.$_POST['drop1'].'<br />Product Description: '.$_POST['jobdescription'];
}
</body>
</html>

 

Edit: You do however realise that you will be getting the ID from the drop down box and not the name? Since you set the value of each option to the id rather than the name, that is what you will receive. This is probably what you want if you are doing anything with a database, but not if you want to display the name.

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.