Form Handling

From: Date: Mon, 30 Oct 2000 02:32:00 +0000
Subject: Form Handling
Groups: php.general 
Request: Send a blank email to php-general+get-22595@lists.php.net to get a copy of this message
I am looking for a little help with HTML form handling with MySQL. I want the HTML to print the correct option from the database when I have a drop-down list. I need PHP to take the answer from the database (let's say it's "05") and print: <SELECT NAME="month"> <OPTION VALUE="01" >01 <OPTION VALUE="02" >02 <OPTION VALUE="03" >03 <OPTION VALUE="04" >04 <OPTION SELECTED VALUE="05" >05 <OPTION VALUE="06" >06- <OPTION VALUE="07" >07 <OPTION VALUE="08" >08 <OPTION VALUE="09" >09 <OPTION VALUE="10" >10 <OPTION VALUE="11" >11 <OPTION VALUE="12" >12 </select> This is what I have thus far: mysql_connect("localhost", "$user", "$password"); mysql_select_db("$database"); $query = mysql_query("SELECT * FROM my_table WHERE (url = '$url')"); $info = mysql_fetch_array($query); // The query gives this result: "2001-05-15" and is assigned to: "$sub_date " $sub_date = $info["submit_date"]; list($submit_year, $submit_month, $submit_day) = split ("-", $sub_date, 10); $month_array = array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"); for($i=0, reset($submit_month); $i<count($month_array); $i++) { echo "<OPTION"; if(current($month_array)==$submit_month) { echo " selected "; next($month_array); } echo " VALUE=\"$submit_month\"> $submit_month\n"; } When it prints the result, it gives: <b>Warning</b>: Variable passed to reset() is not an array or object in <b>/home/internetsubmit.net/www/simplehost/url.php</b> on line <b>17</b><br> <OPTION selected VALUE="01"> 01 <OPTION VALUE="01"> 01 <OPTION VALUE="01"> 01 <OPTION VALUE="01"> 01 <OPTION VALUE="01"> 01 <OPTION VALUE="01"> 01 <OPTION VALUE="01"> 01 <OPTION VALUE="01"> 01 <OPTION VALUE="01"> 01 <OPTION VALUE="01"> 01 <OPTION VALUE="01"> 01 <OPTION VALUE="01"> 01

« previous php.general (#22595) next »