RE: [PHP] Form Handling

From: Date: Mon, 30 Oct 2000 04:39:50 +0000
Subject: RE: [PHP] Form Handling
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-22606@lists.php.net to get a copy of this message
On 30-Oct-00 Robert Abbate wrote: > 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. <snip> > 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); > Is there some reason for this ? ^^^ > $month_array = array("01", "02", "03", "04", > "05", "06", "07", "08", "09", > "10", "11", "12"); > > for($i=0, reset($submit_month); ^^^^^ $submit_month is a scalar, not an array. > $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> And told you so. something from my libhtml.php : ---------------- function selectoption($k, $v, $comp) { printf("<OPTION VALUE=%s %s>%s</OPTION>\n", $k, $comp == $k ? "SELECTED" : "", $v); } function selectlist($name, $ary, $comp) { echo "<SELECT NAME=\"" .$name ."\">\n"; if (isset($ary)) { reset($ary); while (list ($k, $v)= each($ary)) { selectoption($k, $v, $comp); } } echo "</SELECT>\n"; } ------ caller routine: $sub_date = $info["submit_date"]; list($submit_year, $submit_month, $submit_day) = explode('-', $sub_date); $month_array = array( "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" ); selectlist('sel_month' , $month_array, $submit_month); Regards, -- Don Read dread@texas.net There are old sailors, and there are foolish sailors; but damn few old foolish sailors. ---------------------------------------------

« previous php.general (#22606) next »