logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > General
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 01-17-2007, 05:36 AM   #1
red_rose
red_rose's Avatar
 
Join Date: Dec 2006
Location: kuala lumpur, malaysia
Posts: 69
Default retrieving info from db for dropdown

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.


Code:
 
<?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>
red_rose is offline   Reply With Quote
Old 01-17-2007, 03:36 PM   #2
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

firstly remove the @ from the $vars

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

and

@$row['Inst_Id'];
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 01-17-2007, 03:39 PM   #3
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

also

you have this...

Code:
<form name="form1" method="post" action='instituition.php?id=.$row['Inst_Id'].'>
should be like this

Code:
 
<form name="form1" method="post" action='instituition.php?id=<?php echo $row['Inst_Id']; ?>>
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 01-17-2007, 03:50 PM   #4
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

did you spell your table correctly in the SQL statement???
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 01-17-2007, 03:57 PM   #5
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

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
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 01-17-2007, 04:02 PM   #6
red_rose
red_rose's Avatar
 
Join Date: Dec 2006
Location: kuala lumpur, malaysia
Posts: 69
Default

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.
red_rose is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:14 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2021, vBulletin Solutions, Inc.