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>

Link to comment
Share on other sites

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.

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.