Page 1 of 1

Creating a form

Posted: Mon May 26, 2003 5:09 am
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

Posted: Mon May 26, 2003 7:08 am
by volka
please post your current code.

Posted: Mon May 26, 2003 7:54 am
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

Posted: Mon May 26, 2003 9:06 am
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>