Creating a form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jamrop
Forum Commoner
Posts: 80
Joined: Fri May 16, 2003 5:38 pm

Creating a form

Post by jamrop »

Hey,

is it possible to create form , and the options are information from mysql , and when they press the submit button, php will take the selected option and add it to database?

I have tried to do this, but it does a form for each result,

e.g.

for a form i query the database for different types, so u would get

action
sci-fi
horror
etc

and then i add into form the query
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

please post your current code.
jamrop
Forum Commoner
Posts: 80
Joined: Fri May 16, 2003 5:38 pm

Post by jamrop »

hi

the code

Code: Select all

<?php
   $db =mysql_connect("localhost","", "");
mysql_select_db("",$db);

$sql3 = "SELECT *  FROM fansub "; 


$rs3=mysql_query($sql3,$db)or die("Cannot query the database.<br>" . mysql_error());


while ($r3 = mysql_fetch_array($rs3))
{
	$fansub_name=$r3["fansub_name"]; 
	
	$web_link=$r3["web_link"];
	
	$irc=$r3["irc"];
	
?>


  <select name="fansub_name">
   <option value="<?php echo $fansub_name;?>"><?php echo $fansub_name;?></option>
  </select>
  

<?php
}
?>
thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

if you put the <select>-tag within the while-loop for each record a new <select> will be put to the output stream.

Code: Select all

<select name="fansub_name">
<?php
while ($r3 = mysql_fetch_array($rs3))
{
...
?>
   <option value="<?php echo $fansub_name;?>"><?php echo $fansub_name;?></option>
<?php
}
?>
</select>
Post Reply