tuxbuddy Posted April 11, 2008 Share Posted April 11, 2008 I have created a registration page like shown below.In the Project section,I need to let user select from the drop down list.That too should be fetched from the database table called "groups". Can anyone help how gonna I do that Stuff?? File : register.php <html><title>User Registration Page</title> <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <p> <body bgcolor="#d0d0d0"> <img src="helpcore.jpg" align="center"> </p> <form action="insert.php" method="post"> <INPUT TYPE="HIDDEN" NAME="action" VALUE="register"> <DIV ALIGN="CENTER"><CENTER><TABLE BORDER="1" WIDTH="90%"> <h1> User Registration Form</h1> <TR> <TH WIDTH="30%" NOWRAP>Title</TH> <TD WIDTH="70%"> <INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $title ?>" SIZE="8" MAXLENGTH="8"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>First Letters</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="first_letters" VALUE="<?php echo $first_letters ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>First Name</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="firstname" VALUE="<?php echo $firstname ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Middle Name</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="middlename" VALUE="<?php echo $middlename ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Last Name</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="lastname" VALUE="<?php echo $lastname ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Surname</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="surname" VALUE="<?php echo $surname ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Email</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="email" VALUE="<?php echo $email ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Telephone Nr.</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="telnr" VALUE="<?php echo $telnr ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>login Name</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="loginname" VALUE="<?php echo $loginname ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Password</TH> <TD WIDTH="70%"><INPUT TYPE="PASSWORD" <TR> <TH WIDTH="30%" NOWRAP>Project</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="group_id" VALUE="<?php echo $group_id ?>" SIZE="20"></TD> </TR> </table> <input type="submit" value="Submit"> <input type="reset" name="Reset" value="Reset"> </table> </html> Link to comment https://forums.phpfreaks.com/topic/100596-retrieving-data-on-drop-down-list/ Share on other sites More sharing options...
tuxbuddy Posted April 11, 2008 Author Share Posted April 11, 2008 Missed it: The Group table has the following columns: id,name,description,maint_cyclus,sla_level_id,notes Link to comment https://forums.phpfreaks.com/topic/100596-retrieving-data-on-drop-down-list/#findComment-514476 Share on other sites More sharing options...
zenag Posted April 11, 2008 Share Posted April 11, 2008 what fieldname do u want to be in drop down? Link to comment https://forums.phpfreaks.com/topic/100596-retrieving-data-on-drop-down-list/#findComment-514479 Share on other sites More sharing options...
zenag Posted April 11, 2008 Share Posted April 11, 2008 this will display name field from table "groups " <? $sql=mysql_query("select name from groups"); ?> <select name="name"> <? while($row=mysql_fetch_array($sql)) { ?> <option value=""><? echo $row["name"];?></option><? } ?></select> Link to comment https://forums.phpfreaks.com/topic/100596-retrieving-data-on-drop-down-list/#findComment-514481 Share on other sites More sharing options...
tuxbuddy Posted April 11, 2008 Author Share Posted April 11, 2008 Thanks for the code its working but displaying out of table.Can you write the code for me?I tried but wonder where to place the code at right place. Here where I need to put at: <TH WIDTH="30%" NOWRAP>Project</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="group_id" VALUE="<?php echo $group_id ?>" SIZE="20"> <?php include('config.php'); ?><?php $sql=mysql_query("select name from groups"); ?> <select name ="name"> <? while($row=mysql_fetch_array($sql)) { ?> <option value="" ><?echo $row["name"]; ?></options><? } ?></select></td></tr> </table> <input type="submit" value="Submit"> <input type="reset" name="Reset" value="Reset"> </table> I showing both the text box.Will removing the first will enter the same into database correctly. help Me Pls with complete code Link to comment https://forums.phpfreaks.com/topic/100596-retrieving-data-on-drop-down-list/#findComment-514489 Share on other sites More sharing options...
zenag Posted April 11, 2008 Share Posted April 11, 2008 <?php include('config.php'); ?><?php $sql=mysql_query("select name from groups"); ?> <select name ="name"> <? while($row=mysql_fetch_array($sql)) { ?> <option value="" > <? echo $row["name"]; ?> </option><? } ?></select></td></tr> </table> <input type="submit" value="Submit"> <input type="reset" name="Reset" value="Reset"> </table> Link to comment https://forums.phpfreaks.com/topic/100596-retrieving-data-on-drop-down-list/#findComment-514490 Share on other sites More sharing options...
zenag Posted April 11, 2008 Share Posted April 11, 2008 cant get u....tell the problem with code i wl fix it.. Link to comment https://forums.phpfreaks.com/topic/100596-retrieving-data-on-drop-down-list/#findComment-514493 Share on other sites More sharing options...
tuxbuddy Posted April 11, 2008 Author Share Posted April 11, 2008 ya...I got the point but its dsplaying two text box.I need to display only one. What abt VALUE="<?php echo $group_id ?>" SIZE="20"> I think this line is creating a problem. How will I remove that???Pls write me code from Heres my last few lines of code now: <TR> <TH WIDTH="30%" NOWRAP>login Name</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="loginname" VALUE="<?php echo $loginname ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Password</TH> <TD WIDTH="70%"><INPUT TYPE="PASSWORD" NAME="password" SIZE="15"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Project</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="group_id" VALUE="<?php echo $group_id ?>" SIZE="20"> <?php include('config.php'); ?><?php $sql=mysql_query("select name from groups"); ?> <select name ="name"> <? while($row=mysql_fetch_array($sql)) { ?> <option value="" ><?echo $row["name"]; ?></options><? } ?></select></td></tr> </table> <input type="submit" value="Submit"> <input type="reset" name="Reset" value="Reset"> </table> </html> Link to comment https://forums.phpfreaks.com/topic/100596-retrieving-data-on-drop-down-list/#findComment-514496 Share on other sites More sharing options...
zenag Posted April 11, 2008 Share Posted April 11, 2008 thinh this might help.... <?php $con=mysql_connect("localhost","root",""); mysql_select_db("test",$con); $sql=mysql_query("select name from user"); ?> <TR> <TH WIDTH="30%" NOWRAP>login Name</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="loginname" VALUE="<?php echo $loginname ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Password</TH> <TD WIDTH="70%"><INPUT TYPE="PASSWORD" NAME="password" SIZE="15"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Project</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="group_id" VALUE="<?php echo $group_id ?>" SIZE="20"> <select name ="name"> <? while($row=mysql_fetch_array($sql)) { ?> <option value="" ><?echo $row["name"]; ?></option><? } ?></select></td></tr> </table> <input type="submit" value="Submit"> <input type="reset" name="Reset" value="Reset"> </table> </html> Link to comment https://forums.phpfreaks.com/topic/100596-retrieving-data-on-drop-down-list/#findComment-514499 Share on other sites More sharing options...
tuxbuddy Posted April 11, 2008 Author Share Posted April 11, 2008 Heyy....Again its not solved..Displaying two textboxes. in front of Project.....Here;s the complete code: <html><title>User Registration Page</title> <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <p> <body bgcolor="#d0d0d0"> <img src="helpcore.jpg" align="center"> </p> <form action="insert.php" method="post"> <INPUT TYPE="HIDDEN" NAME="action" VALUE="register"> <DIV ALIGN="CENTER"><CENTER><TABLE BORDER="1" WIDTH="90%"> <h1> User Registration Form</h1> <?php $con=mysql_connect("localhost","root","mysql123"); mysql_select_db("helpcore",$con); $sql=mysql_query("select name from groups"); ?> <TR> <TH WIDTH="30%" NOWRAP>Title</TH> <TD WIDTH="70%"> <INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $title ?>" SIZE="8" MAXLENGTH="8"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>First Letters</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="first_letters" VALUE="<?php echo $first_letters ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>First Name</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="firstname" VALUE="<?php echo $firstname ?>" SIZE="20"></TD> VALUE="<?php echo $firstname ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Middle Name</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="middlename" VALUE="<?php echo $middlename ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Last Name</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="lastname" VALUE="<?php echo $lastname ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Surname</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="surname" VALUE="<?php echo $surname ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Email</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="email" VALUE="<?php echo $email ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Telephone Nr.</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="telnr" VALUE="<?php echo $telnr ?>" SIZE="20"></TD> </TR> <TR> <TR> <TH WIDTH="30%" NOWRAP>login Name</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="loginname" VALUE="<?php echo $loginname ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Password</TH> <TD WIDTH="70%"><INPUT TYPE="PASSWORD" NAME="password" SIZE="15"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Project</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="group_id" --------<<< POINT OF INTEREST VALUE="<?php echo $group_id ?>" SIZE="20">[/color]<select name ="name"> <? while($row=mysql_fetch_array($sql)) { ?> <option value="" ><?echo $row["name"]; ?></options><? } ?></select></td></tr> </table> <input type="submit" value="Submit"> <input type="reset" name="Reset" value="Reset"> </table> </html> Link to comment https://forums.phpfreaks.com/topic/100596-retrieving-data-on-drop-down-list/#findComment-514501 Share on other sites More sharing options...
tuxbuddy Posted April 11, 2008 Author Share Posted April 11, 2008 Its Done.I simply removed the line <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="group_id" VALUE="<?php echo $group_id ?>" SIZE="20"> and now the code is <TR> <TH WIDTH="30%" NOWRAP>Project</TH> <TD WIDTH="70%"><select name ="name"> <? while($row=mysql_fetch_array($sql)) { ?> <option value="" ><?echo $row["name"]; ?></options><? } ?></select> </td></tr> </table> <input type="submit" value="Submit"> <input type="reset" name="Reset" value="Reset"> </table> But tell me one thing...Earlier I was storing the Project value which the user inputs into one table BUt how will I fetch this by which name. Pls Help Link to comment https://forums.phpfreaks.com/topic/100596-retrieving-data-on-drop-down-list/#findComment-514504 Share on other sites More sharing options...
zenag Posted April 11, 2008 Share Posted April 11, 2008 it works fine for me.......... <?php $con=mysql_connect("localhost","root","mysql123"); mysql_select_db("helpcore",$con); $sql=mysql_query("select name from groups"); ?> <html><title>User Registration Page</title> <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <p> <body bgcolor="#d0d0d0"> <img src="helpcore.jpg" align="center"> </p> <form action="insert.php" method="post"> <!--<INPUT TYPE="HIDDEN" NAME="action" VALUE="register">--> <DIV ALIGN="CENTER"><CENTER> <TABLE BORDER="1" WIDTH="90%"> <h1> User Registration Form</h1> <TR> <TH WIDTH="30%" NOWRAP>Title</TH> <TD WIDTH="70%"> <INPUT TYPE="TEXT" NAME="title"VALUE="<?php echo $title ?>" SIZE="8" MAXLENGTH="8"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>First Letters</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="first_letters" VALUE="<?php echo $first_letters ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>First Name</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="firstname" VALUE="<?php echo $firstname ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Middle Name</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="middlename" VALUE="<?php echo $middlename ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Last Name</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="lastname" VALUE="<?php echo $lastname ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Surname</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="surname" VALUE="<?php echo $surname ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Email</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="email" VALUE="<?php echo $email ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Telephone Nr.</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="telnr" VALUE="<?php echo $telnr ?>" SIZE="20"></TD> </TR> <TR> <TR> <TH WIDTH="30%" NOWRAP>login Name</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="loginname" VALUE="<?php echo $loginname ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Password</TH> <TD WIDTH="70%"><INPUT TYPE="PASSWORD" NAME="password" SIZE="15"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Project</TH> <TD WIDTH="70%"> <INPUT TYPE="TEXT" NAME="group_id"VALUE="<?php echo $group_id ?>" SIZE="20"></TD></TR> <TR> <TH WIDTH="30%" NOWRAP>Project</TH> <TD WIDTH="70%"><select name ="name"> <? while($row=mysql_fetch_array($sql)) { ?> <option value="" ><? echo $row["name"]; ?></options><? } ?></select></TD></TR> </table> <input type="submit" value="Submit"> <input type="reset" name="Reset" value="Reset"> </table> </html> Link to comment https://forums.phpfreaks.com/topic/100596-retrieving-data-on-drop-down-list/#findComment-514506 Share on other sites More sharing options...
tuxbuddy Posted April 11, 2008 Author Share Posted April 11, 2008 Superb..Dude.Thanks a lot. Link to comment https://forums.phpfreaks.com/topic/100596-retrieving-data-on-drop-down-list/#findComment-514510 Share on other sites More sharing options...
tuxbuddy Posted April 11, 2008 Author Share Posted April 11, 2008 Wait...One minute...Still In trouble. Now your code displays two projects...Heeyyyy I need it to display : Project |-----------| only once .... But is displays project two times. Pls Help Link to comment https://forums.phpfreaks.com/topic/100596-retrieving-data-on-drop-down-list/#findComment-514522 Share on other sites More sharing options...
zenag Posted April 11, 2008 Share Posted April 11, 2008 i think its just the heading <?php $con=mysql_connect("localhost","root","mysql123"); mysql_select_db("helpcore",$con); $sql=mysql_query("select name from groups"); ?> <html><title>User Registration Page</title> <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <p> <body bgcolor="#d0d0d0"> <img src="helpcore.jpg" align="center"> </p> <form action="insert.php" method="post"> <!--<INPUT TYPE="HIDDEN" NAME="action" VALUE="register">--> <DIV ALIGN="CENTER"><CENTER> <TABLE BORDER="1" WIDTH="90%"> <h1> User Registration Form</h1> <TR> <TH WIDTH="30%" NOWRAP>Title</TH> <TD WIDTH="70%"> <INPUT TYPE="TEXT" NAME="title"VALUE="<?php echo $title ?>" SIZE="8" MAXLENGTH="8"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>First Letters</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="first_letters" VALUE="<?php echo $first_letters ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>First Name</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="firstname" VALUE="<?php echo $firstname ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Middle Name</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="middlename" VALUE="<?php echo $middlename ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Last Name</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="lastname" VALUE="<?php echo $lastname ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Surname</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="surname" VALUE="<?php echo $surname ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Email</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="email" VALUE="<?php echo $email ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Telephone Nr.</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="telnr" VALUE="<?php echo $telnr ?>" SIZE="20"></TD> </TR> <TR> <TR> <TH WIDTH="30%" NOWRAP>login Name</TH> <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="loginname" VALUE="<?php echo $loginname ?>" SIZE="20"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Password</TH> <TD WIDTH="70%"><INPUT TYPE="PASSWORD" NAME="password" SIZE="15"></TD> </TR> <TR> <TH WIDTH="30%" NOWRAP>Project</TH> <TD WIDTH="70%"> <INPUT TYPE="TEXT" NAME="group_id"VALUE="<?php echo $group_id ?>" SIZE="20"></TD></TR> <TR> <TH WIDTH="30%" NOWRAP>list</TH> <TD WIDTH="70%"><select name ="name"> <? while($row=mysql_fetch_array($sql)) { ?> <option value="" ><? echo $row["name"]; ?></options><? } ?></select></TD></TR> </table> <input type="submit" value="Submit"> <input type="reset" name="Reset" value="Reset"> </table> </html> Link to comment https://forums.phpfreaks.com/topic/100596-retrieving-data-on-drop-down-list/#findComment-514542 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.