Rifts Posted November 25, 2009 Share Posted November 25, 2009 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 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 Quote Link to comment https://forums.phpfreaks.com/topic/182940-drop-down-box-database-extraction/ Share on other sites More sharing options...
abazoskib Posted November 25, 2009 Share Posted November 25, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/182940-drop-down-box-database-extraction/#findComment-965648 Share on other sites More sharing options...
Rifts Posted November 26, 2009 Author Share Posted November 26, 2009 Ok I did what you said... I have a dropdown form named "dropdown" and when i do <?php echo $_POST['dropdown']; ?> i get this error: Notice: Undefined index: dropdown in C:\wamp\www\homepage\google.php on line 137 Quote Link to comment https://forums.phpfreaks.com/topic/182940-drop-down-box-database-extraction/#findComment-965749 Share on other sites More sharing options...
Rifts Posted November 26, 2009 Author Share Posted November 26, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/182940-drop-down-box-database-extraction/#findComment-965769 Share on other sites More sharing options...
abazoskib Posted November 26, 2009 Share Posted November 26, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/182940-drop-down-box-database-extraction/#findComment-965784 Share on other sites More sharing options...
Rifts Posted November 26, 2009 Author Share Posted November 26, 2009 yes that does work but say i wanted to pull their sign up data which is stored in my db as "date" if I do this echo $dropdown['date']; the only this is echos is the first letter of their first name and i have no idea why Quote Link to comment https://forums.phpfreaks.com/topic/182940-drop-down-box-database-extraction/#findComment-965786 Share on other sites More sharing options...
rotc_rachel Posted November 26, 2009 Share Posted November 26, 2009 What does your HTML code look like for the form? Quote Link to comment https://forums.phpfreaks.com/topic/182940-drop-down-box-database-extraction/#findComment-965794 Share on other sites More sharing options...
Rifts Posted November 26, 2009 Author Share Posted November 26, 2009 <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" /> Quote Link to comment https://forums.phpfreaks.com/topic/182940-drop-down-box-database-extraction/#findComment-965795 Share on other sites More sharing options...
rotc_rachel Posted November 26, 2009 Share Posted November 26, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/182940-drop-down-box-database-extraction/#findComment-965797 Share on other sites More sharing options...
Rifts Posted November 26, 2009 Author Share Posted November 26, 2009 I'm totally open to rewriting the drop down box code so it will make it easier if anyone would want to help me with that.... Quote Link to comment https://forums.phpfreaks.com/topic/182940-drop-down-box-database-extraction/#findComment-965805 Share on other sites More sharing options...
Rifts Posted November 26, 2009 Author Share Posted November 26, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/182940-drop-down-box-database-extraction/#findComment-965823 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.