Page 1 of 1

Pass variable to next page using GET

Posted: Tue Jun 01, 2010 4:37 pm
by djs1971
Complete newbie - have battled with this all day and going nowhere - completely stumped so throwing myself on your mercy!!

I have a simple form which has a select drop down populated from my sql database. When I hit submit nothing seems to get passed to the hidden field in the next page.

My code for the form is as follows:

<form action="selectday.php" method="get">
<select>

<?php

//connect to MySQL

$connect = mysql_connect("localhost","root","") or
die ("Could not connect to database.");

//choose the database

mysql_select_db("lakeside");

//Query from database

$sql="SELECT year_id, year FROM years";
$result=mysql_query($sql);

$options="";

while ($row=mysql_fetch_array($result)) {

$year_id=$row["year_id"];
$year=$row["year"];
$options.="<OPTION VALUE=\"$year_id\">".$year.'</option>';
}
?>

<SELECT NAME=year_id>
<OPTION VALUE=0>Choose Year Group
<?=$options?>
</SELECT>

<input type="submit" />

</select>
</form>

I believe by using GET I should see the data passed in the url?? Any advice would be great!

Re: Pass variable to next page using GET

Posted: Tue Jun 01, 2010 4:44 pm
by requinix
It might have something to do with the invalid HTML you're using. What's up with that lone <select>?

Re: Pass variable to next page using GET

Posted: Tue Jun 01, 2010 4:48 pm
by djs1971
You Sir are a legend. I've tried several ways of doing this today and at some point during cutting/pasting code and changing things must have left that lone select there. Think you've cracked it. Thanks :-)