Jump to content

Help needed with populating a drop down menu from mysql database


shalli

Recommended Posts

Hi there

 

I am trying to pre-populate two drop down menus from a mysql database but I keep getting a blank drop down menu for the franchise name. Please can some one help?!?!?!?!?

 

I am pasting my code below. Any help will be greatly appreciated

 

thanks

 

<?php

 

$host="localhost"; // Host name

$username="xxxx"; // Mysql username

$password="xxxx"; // Mysql password

$db_name="xxxx"; // Database name

 

// Connect to server and select databse.

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

//See if there is a table that you require...

$tbl_name = 'franchises';

if( mysql_num_rows( mysql_query("SHOW TABLES LIKE '".$tbl_name."'")))

{

//print("Found Table. Ready to proceed!<br>");

}else{

print("Table was not found, I will create it now.<br>");

}

//select franchise so ID is auto populated

$franchiseSQL = "SELECT id, name FROM franchises";

$result = mysql_query($franchiseSQL);

 

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

//{

//echo "Franchise Id :{$row['id']} <br>" ;

//echo "Franchise Name :{$row['name']} <br>" ;

//}

 

 

?>

 

 

<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">

<tr>

<form name="form1" method="post" action="checklogin.php">

<td>

<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">

<tr>

<td colspan="3"><strong>Member Login </strong></td>

</tr>

<tr>

<td width="78">Username</td>

<td width="6">:</td>

<td width="294"><input name="myusername" type="text" id="myusername"></td>

</tr>

<tr>

<td>Password</td>

<td>:</td>

<td><input name="mypassword" type="text" id="mypassword"></td>

</tr>

<tr>

<td>Name</td>

<td>:</td>

<td><input name="myname" type="text" id="myname"></td>

</tr>

<tr>

<td>Website</td>

<td>:</td>

<td><input name="mywebsite" type="text" id="mywebsite"></td>

</tr>

<tr>

<td>HeaderBGColour</td>

<td>:</td>

<td><input name="headerBGColour" type="text" id="headerBGColour"></td>

</tr>

<tr>

<td>Logo</td>

<td>:</td>

<td><input name="logolocation" type="text" id="logolocation"></td>

</tr>

<tr>

<tr>

<td>Franchise ID</td>

<select name="id" id="id" />

<? while($row = mysql_fetch_array($result)) { ?>

echo "<option value=\"".$row['id']."\">" .$row['id']."</option>";

//<option value="<? echo $row['id']; ?>"><?php echo $row['id']; ?></option>

<? } ?>

</select>

<br />

</tr>

</tr>

<tr>

<tr>

<td>Franchise Name</td>

<select name="name" id="name" />

<? while ($row = mysql_fetch_array($result)) { ?>

echo "<option value=\"".$row['name']."\">" .$row['name']."</option>";

//<option value="<? echo $row['name']; ?>"><?php echo $row['name']; ?></option>

<? } ?>

</select>

<br />

</tr>

<tr>

<td> </td>

<td> </td>

<td><input type="submit" name="Submit" value="Login"></td>

</tr>

</table>

</td>

</form>

</tr>

</table>

In two places in the form you break php then try to echo

 

<? while($row = mysql_fetch_array($result)) { ?>

echo "<option value=\"".$row['id']."\">" .$row['id']."</option>";

//<option value="<? echo $row['id']; ?>"><?php echo $row['id']; ?></option>

<? } ?>

 

 

 

HTH

Teamatomic

<? while ($row = mysql_fetch_array($result)) { ?>
echo "<option value=\"".$row['name']."\">" .$row['name']."</option>";
//<option value="<? echo $row['name']; ?>"><?php echo $row['name']; ?></option>
<? } ?>

 

Should be: (take spaces out between single quotes and double quotes, I put them there only so you could see better)

 

<? 
while ($row = mysql_fetch_array($result)) {
   echo "<option value=' ".$row['name']." '>".$row['name']."</option>";
} 
?>

Hi

 

Thanks teamatomic and TapeGun007 for your responses to my php problem but it hasnt made a difference. I am still getting a blank drop down menu?!?!?!?!?!

 

any ideas

 

Thanks for your time greatly appreciated

 

cheers

 

shalli

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.