PDA

View Full Version : retrieving info from db for dropdown


red_rose
01-17-2007, 05:36 AM
hello there,

i have a problem with my script. i would like to retrieve information from db to be displayed in my dropdown but it's not functioning. whenever i run this page, i can only see one option and that is "Select Instituition". i can't see the instituition names that i have in my db. could anyone tell me what's wrong with my code? thank you so much.



<?php

@$inst = $_POST['inst'];

if($inst) {
///////////////////////////////////////////////////////////////////////////
$query = sprintf("SELECT * FROM instituition");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
///////////////////////////////////////////////////////////////////////////
}

?>

<html>
<head>
<title>:: Welcome ::</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

<form name="form1" method="post" action='instituition.php?id=.$row['Inst_Id'].'>
<select name="inst">
<option value="" selected>Select Instituition</option>
<?php do { ?>
<option value="<?php echo @$row['Inst_Id']; ?>"><?php echo @$row['InstName']; ?></option>
<?php } while ($row = mysql_fetch_array($result)); ?>
</select>
<input name="Go" type="submit" id="Go" value="Go">
</form>

</body>
</html>

davidj
01-17-2007, 03:36 PM
firstly remove the @ from the $vars

@$inst = $_POST['inst'];

and

@$row['Inst_Id'];

davidj
01-17-2007, 03:39 PM
also

you have this...

<form name="form1" method="post" action='instituition.php?id=.$row['Inst_Id'].'>

should be like this


<form name="form1" method="post" action='instituition.php?id=<?php echo $row['Inst_Id']; ?>>

davidj
01-17-2007, 03:50 PM
did you spell your table correctly in the SQL statement???

davidj
01-17-2007, 03:57 PM
your logic is ilogical

remove the IF statement

your $inst is empty so the SQL cant fire

and the SQL needs to fire to populate the $inst variable

red_rose
01-17-2007, 04:02 PM
hello david,

thanks alot for your help. the tables are spelled correctly. yeah, the problem is with the if statement. i shouldn't have put that. by looking at the video, i thought it was necessary to put but yeah it's working now. thanks alot, i really appreciate it.