Problems with populating forms with queried information
Moderator: General Moderators
Problems with populating forms with queried information
Hello. I have figured out how to put information into a form that I have queried from the database. I have done so with txtboxes. How would I do something like that for a dropdown menu. or even a radio button??? There are quite a few drop down menus in the form, but this is one of them. What we are going to do is allow the user to select his/her title and store it in the database. The user will then have an option to view their information, and the only thing I want to see is just the value stored in the database...
Please help...
Here is my code.
<select name="mnuTitle" id="mnuTitle">
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Ms">Ms</option>
<option value="Dr">Dr</option>
</select>
Thank you.
Please help...
Here is my code.
<select name="mnuTitle" id="mnuTitle">
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Ms">Ms</option>
<option value="Dr">Dr</option>
</select>
Thank you.
-
The Monkey
- Forum Contributor
- Posts: 168
- Joined: Tue Mar 09, 2004 9:05 am
- Location: Arkansas, USA
ALRIGHT! Something I can help with! w00t
Ok.
I'm going to assume you are using the Post method.
Insert this code into your php script:
Now, you have more variables to insert into the database, I'm sure. If you would like to post your exact code you have so far I would be glad to finish it up with the $mnuTitle code I posted above!
Now, I'm not sure how much php you know, but the above code won't work unless you first hook it up with your script and make some changes to it!
Hope I've helped!
Ok.
I'm going to assume you are using the Post method.
Insert this code into your php script:
Code: Select all
<?php
$mnuTitle = $_POST['mnuTitle'];
$sql_query = "INSERT $mnuTitle INTO tablename";
$sql_result = mysql_query($sql_query);
?>Now, I'm not sure how much php you know, but the above code won't work unless you first hook it up with your script and make some changes to it!
Hope I've helped!
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
<select name="mnuTitle" id="mnuTitle">
<?
while ( $row = mysql_fetch_array($result) ) {
$value= $row["value"];
$select= $row["select"];
echo "<option value="$value">$select</option>";
}
?>
</select><select name="mnuTitle" id="mnuTitle">
<?
while ( $row = mysql_fetch_array($result) ) {
$value= $row["value"];
$select= $row["select"];
echo "<option value=\"$value\">$select</option>";
}
?>
</select>
I tried the code that was posted up by Phenom. Whenever I do this in my drop down box I have $select print out. I tried putting this in quotes and other various techniques, but for some reason it things that it is a string, but we need it to recognize that it's a variable....
Please help,,
Thank you
<?
while ( $row = mysql_fetch_array($result) ) {
$value= $row["value"];
$select= $row["select"];
echo "<option value=\"$value\">$select</option>";
}
?>
</select>
I tried the code that was posted up by Phenom. Whenever I do this in my drop down box I have $select print out. I tried putting this in quotes and other various techniques, but for some reason it things that it is a string, but we need it to recognize that it's a variable....
Please help,,
Thank you
Code: Select all
<?php
( $row = mysql_fetch_array($result)
?>like something:
Code: Select all
<?php
$sql = "SELECT * FROM table_name";
$result= mysql_query($sql);
// etc etc
?>Yes, I am able to query the database and populate forms with text information, for instance a first or last name.....But as for a drop down menu, I can't get it to work. Lets say for example a person selects one state from a drop down menu. When a user is done and clicks submit that information is stored in the database. That works fine. That one state that the user picked is stored in the database. Now, the user will be able to view his or her information in the database. How do I select that state from the database and put it in a dropdown....Just that one state.
When I try the code..
<select name="mnuTitle" id="mnuTitle">
$temp = $rows['State'];
$select = $rows['State'];
<option value="$temp">$select</option>
</select>
This will create drop down menu in my form and put the $select into it. But I want the state.
Please help
When I try the code..
<select name="mnuTitle" id="mnuTitle">
$temp = $rows['State'];
$select = $rows['State'];
<option value="$temp">$select</option>
</select>
This will create drop down menu in my form and put the $select into it. But I want the state.
Please help
$query = 'SELECT * from MEMBER, ADDRESS, HONORARY, INITIATION';
$result = mysql_query($query);
$numRows = mysql_num_rows($result);
if($numRows > 0)
{
while($rows = mysql_fetch_array($result))
{
echo '<form action="" method="post">
<table width="98%" border="0" align="center" cellspacing="2">
<tr>
<td width="20%">Title:</td>
<td colspan="2"> <select name="mnuTitle" id="mnuTitle">
$temp = $rows['State'];
$select = $rows['State'];
<option value="$temp">$select</option>
</select></td>
<td width="17%">First Name:</td>
<td width="34%"><input name="txtFirstName" type="text" id="txtFirstName2" value="'.$rows['Name_First'].'"></td>
</tr>
$result = mysql_query($query);
$numRows = mysql_num_rows($result);
if($numRows > 0)
{
while($rows = mysql_fetch_array($result))
{
echo '<form action="" method="post">
<table width="98%" border="0" align="center" cellspacing="2">
<tr>
<td width="20%">Title:</td>
<td colspan="2"> <select name="mnuTitle" id="mnuTitle">
$temp = $rows['State'];
$select = $rows['State'];
<option value="$temp">$select</option>
</select></td>
<td width="17%">First Name:</td>
<td width="34%"><input name="txtFirstName" type="text" id="txtFirstName2" value="'.$rows['Name_First'].'"></td>
</tr>
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
The whole long wrong echo line that echos the form and table and stuff should be before your do the while. If its in the while then its going to add that over and over again. Same for the last bit. All you need in the while loop is
$temp = $rows['State'];
$select = $rows['State'];
<option value="$temp">$select</option>
And just so you now, you can't just put HTML in wiht your php code. You either need to echo it out, or end your php tags and have teh HTML and then start your PHP tags back.
$temp = $rows['State'];
$select = $rows['State'];
<option value="$temp">$select</option>
And just so you now, you can't just put HTML in wiht your php code. You either need to echo it out, or end your php tags and have teh HTML and then start your PHP tags back.
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm