Jump to content

Retrieving Data on Drop Down List??


tuxbuddy

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
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.