Jump to content

Recommended Posts

I asked this question yesterday but I think I gave way to much information making the question very confusing so i'm asking it again in a much simpler way  :D

 

ok I have a drop down box with 3 names when i pick a name and click submit i want just information i have stored in the database of  the persons name who i picked to show up on the next screen

 

I already have the drop down box working i dont know what to do from there

Link to comment
https://forums.phpfreaks.com/topic/182940-drop-down-box-database-extraction/
Share on other sites

well, you need to create a form, with a submit button. Pick a method, whether it be POST or GET. Then once you submit the form you will be able to access the choice you make on the drop down. For example if your drop down has a NAME attribute of "my_drop_down" and you are using POST to send the data, you will be able to access the value through $_POST['my_drop_down']; There are tons of tutorials(I think even here on PHPFreaks) on how to handle forms with PHP.

ok i half way got it working... its posting the name i selected from the drop box but I cant figure out how to get any of the saved information from the database on that specific user..

 

for example i tried

<?php 
    $dropdown = $_POST['dropdown'];
    echo $dropdown['firstname'];
	?>

 

and it only displays the first letter of the first name?

ok i half way got it working... its posting the name i selected from the drop box but I cant figure out how to get any of the saved information from the database on that specific user..

 

for example i tried

<?php 
    $dropdown = $_POST['dropdown'];
    echo $dropdown['firstname'];
	?>

 

and it only displays the first letter of the first name?

 

<?php 
    $dropdown = $_POST['dropdown'];
    echo $dropdown;
	?>

That should work.

<form id="loginForm" name="dropdown1" method="post" action="google.php">
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("clients", $con);

    
$extract = mysql_query ("SELECT * FROM members ORDER BY `date` DESC");
$numrows = mysql_num_rows ($extract);

echo"Select USER: <select name='dropdown'>";

while ($row = mysql_fetch_assoc($extract))
{
  echo '<option name="'.$row['firstname'].'">'.$row['login'].' </option>';
}      


?>
<input type="submit" name="Submit" />

So when you choose a selection, your form executes to a page called google.php. 

Try storing what they pick in a variable from $_POST and then on the google.php do a

 

SELECT * FROM database WHERE firstname = '$variable'

 

Then just display that?

 

I'm not sure if that is what you were going for, your code makes it a bit more compact.  I'm guessing it has something to do with the WHILE loop if it's only showing one char of the string though.

So when you choose a selection, your form executes to a page called google.php. 

Try storing what they pick in a variable from $_POST and then on the google.php do a

 

SELECT * FROM database WHERE firstname = '$variable'

 

Then just display that?

 

I'm not sure if that is what you were going for, your code makes it a bit more compact.  I'm guessing it has something to do with the WHILE loop if it's only showing one char of the string though.

 

 

yeah it just doesn't work at all... no matter what i try to pull from the data base it will only pull the first letter of whatever was selected... i have no idea what to do

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.