Forum Moderators: coopster

Message Too Old, No Replies

PHP Dynamic Drop Down

dynamic drop down and passing page ID

         

godsteruk

9:54 pm on Mar 10, 2009 (gmt 0)

10+ Year Member



Hi guys.

New to the forums so please go gentle....

Esentially i'm trying to create a PHP based dynamic drop down that would page the selected items ID from the mySQL database to a subsequent details page via the hyperlink.

i.e.

User selects an item from the drop down, which populates with my categories.

When selecting 'Submit' the corresponding ID for that category is passed in the URL to the details page.

I have got the catagories to load and appear in the drop down, yet on selecting a category and hitting the button I get a blank template for the corresponding page as no value was passed for the page ID.

Please help as i'm sure its something quite trivial i'm missing.

Code as below:

<?php include 'dbconnect.php' ?>

<?php
// If submitted, check the value of "select". If its not blank value, get the value and put it into $select.
if(isset($select)&&$select!=""){
$select=$_POST['select'];
}
?>
<form id="form1" name="form1" method="post" action="cat_conventional_sheet.php?intCatID=<?php echo $select; ?>">
Please select a category:
<select name="select">
<option value="">--- Category ---</option>
<?
// Get records from database
$sqlCats = "SELECT c.*
FROM pv_topic t
JOIN pv_topicxcat txc ON t.intTopicID = txc.intTopicID
JOIN pv_cat c ON c.intCatID = txc.intCatID
WHERE t.intTopicID = 2";

$qryCats = mysql_query($sqlCats);

//Check to see if query came back empty
$rows = @mysql_num_rows($qryCats);

if(!$rows)
{
do_error("No record available!");
}
else {
// Show records by while loop.
while ($myrow = mysql_fetch_array($qryCats)) {

$intCatID = $myrow["intCatID"];
$strCatName = $myrow["strName"];
$strCatLatinName = $myrow["strLatinName"];

?>
<option value="<? echo $myrow['intCatID']; ?>" <? if($myrow['intCatID']==$select){ echo "selected"; } ?>><? echo $strCatName; ?></option>
<?
// End while loop
}
//End else
}
?>
</select>
<input type="submit" name="Submit" value="Select" />
</form>
<?php
// Close database connection.
mysql_close();
?>

dreamcatcher

8:18 am on Mar 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi godsteruk, welcome to WebmasterWorld. :)

If you have register globals OFF (which it sounds like you do), you need to access all POST vars via the superglobal array $_POST.

So, this line:

if(isset($select)&&$select!="")

Should be:

if(isset($_POST['select'])&&$_POST['select']!="")

Does that help?

dc