Pass variable to next page using GET

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
djs1971
Forum Newbie
Posts: 14
Joined: Tue Jun 01, 2010 4:33 pm

Pass variable to next page using GET

Post 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!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Pass variable to next page using GET

Post by requinix »

It might have something to do with the invalid HTML you're using. What's up with that lone <select>?
djs1971
Forum Newbie
Posts: 14
Joined: Tue Jun 01, 2010 4:33 pm

Re: Pass variable to next page using GET

Post 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 :-)
Post Reply