adicrst Posted March 16, 2008 Share Posted March 16, 2008 I still can't figuer it out how to make all the informations in a colomn from the mysql table to show up in a drop down box.this is a drop down box <form action=""><select name="cars"><option value="volvo">Volvo</option><option value="saab">Saab</option><option value="fiat" selected="selected">Fiat</option><option value="audi">Audi</option></select></form> and this is the select statement $result = mysql_query("SELECT * FROM person");while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; } how can i make all the FIRSTNAME to show in a drop down box ? Link to comment Share on other sites More sharing options...
Peppe L-G Posted March 16, 2008 Share Posted March 16, 2008 <form action=""> <select name="cars"> <?php while($row = mysql_fetch_array($result)){ echo '<option>'.$row['FirstName'].'</option>'; } ?> </select></form> Link to comment Share on other sites More sharing options...
adicrst Posted March 16, 2008 Author Share Posted March 16, 2008 i got to do this and it's showing the names from a table, but i tried to make it show me the selected name after clicking the button, but it doesn't work. What am i doing wrong ? <?php $con = mysql_connect("localhost","root",""); if (!$con) { die ("No connection".mysql_error()); }mysql_select_db("test",$con);$query="SELECT name,id FROM student";$result=mysql_query($query);echo "<form action=''><select name='student'>";while($nt=mysql_fetch_array($result)) { echo "<option value=$nt[id]>$nt[name]</option>"; }echo "</select><input type='submit' name='trimite'></form>";if ($_POST['trimite']== true) { echo "Your name is: ".$_POST['student']; }?> Link to comment Share on other sites More sharing options...
Peppe L-G Posted March 16, 2008 Share Posted March 16, 2008 I think the fault is the attributes in your form.In this case, the action must have the value as the filename (example: form.php).And <form> also have the the attribute method, which should have the value "post", if you later use $_POST in PHP. Link to comment Share on other sites More sharing options...
adicrst Posted March 16, 2008 Author Share Posted March 16, 2008 ok, thanks for the hints, it helped alot and i saw what mistakes i made. Here is the corect and working form <?php $con = mysql_connect("localhost","root",""); if (!$con) { die ("No connection".mysql_error()); }mysql_select_db("test",$con);$query="SELECT name,id FROM student";$result=mysql_query($query);echo "<form action='index.php' method='post'><select name='student'>";while($nt=mysql_fetch_array($result)) { echo "<option value=$nt[name]>$nt[name]</option>"; }echo "</select><input type='submit' name='trimite'></form>";if (isset($_POST['trimite'])) { echo "Your name is: ".$_POST['student']; }?> thanks again Link to comment Share on other sites More sharing options...
adicrst Posted March 16, 2008 Author Share Posted March 16, 2008 another problem, sry for the double posting. At the above code, the problem is that if the name is Max John, the output in the IF statement is "Your name is: Max" (and the rest of the name isn't displayed)here is a database if someone wants to have a quick try DATABASE*how do i make it to show the full selected name* i also tried to delete the selected record, but doesn't work. What's wrong with this part ?first if (isset($_POST['trimite'])){ echo "Your name is: ".$_POST['student'];} Try to delete the selected record if (isset($_POST['trimite'])) { echo "Your name is: ".$_POST['student']; $delete_name=$_POST['student']; mysql_query("DELETE FROM student WHERE name=$delete_name"); } Link to comment Share on other sites More sharing options...
justsomeguy Posted March 17, 2008 Share Posted March 17, 2008 You need quotes around the value. When in doubt, view the HTML source that PHP generates to see what it's doing. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.