Jump to content

NewBe Help with Dropdown box from MYSQL database


nezbo

Recommended Posts

I have tryed it and i cant get it to work  :'(

 

this is my code what is going wrong?

 

 

 

 

$getSiteName = mysql_query("SELECT SiteName FROM site");

if (!$getSiteName)

{

  echo 'Could not run query: ' . mysql_error();

  exit;

}

 

echo "<table align=center border=0><tr>";

echo "<tr><td colspan=2 align=center><h2>Log a Job</h2><tr><td>";

echo "<form action=doLogJob.php method=post>";

echo "<tr><td align=left>Current User : <td align=left>" . $_COOKIE["user"] . "</td></tr>";

echo "<tr><td align=left>PCIU Number : <td align=left><input type=text NAME=pciuno></td></tr>";

echo "<tr><td align=left>Site Name : <td align=left><select NAME=SiteName1></td></tr>";

  while($row = mysql_fetch_array()) {

 

      echo "<option value='please select a site', $row>$row</option>";

 

  }

echo "<tr><td align=left>Reported By : <td align=left><input type=text NAME=RepBy></td></tr>";

echo "<tr><td align=left VALIGN=top>Problem :<td align=left> <TEXTAREA NAME=Problem ROWS=17 COLS=70></TEXTAREA></td></tr>";

echo "<tr><td align=left>Date : <td align=left><input type=text NAME=callDate value='$callDate'></td></tr>";

echo "<tr><td align=left>Time : <td align=left><input type=text NAME=callTime value='$callTime'></td></tr>";

echo "<tr><td><input type=submit value=Submit><td><input type=reset name=Reset value=Reset></td></tr>";

echo "</form>";

echo "</tr></table>";

 

you dont seem to of defined $row.

 

it seems to be missing something like

 

$row=($row['sitename']);

 

try this:

 

	
<?php
$query="select <your data> from <your table> where <your criteria>";
$result=mysql_query($query);
if (!$result)
{
die(mysql_error());
}
$num_rows=mysql_num_rows($result);



echo "<table align=center border=0><tr>";
echo "<tr><td colspan=2 align=center><h2>Log a Job</h2><tr><td>";
echo "<form action=doLogJob.php method=post>";
echo "<tr><td align=left>Current User : <td align=left>" . $_COOKIE["user"] . "</td></tr>";
echo "<tr><td align=left>PCIU Number : <td align=left><input type=text NAME=pciuno></td></tr>";
echo "<tr><td align=left>Site Name : <td align=left><select NAME=SiteName1>";
   	 while ($row=mysql_fetch_array($result)){
    $row=($row['<your row name>']);
      echo "<option value='please select a site', $row>$row</option>";

   }
echo "<tr><td align=left>Reported By : <td align=left><input type=text NAME=RepBy></td></tr>";
echo "<tr><td align=left VALIGN=top>Problem :<td align=left> <TEXTAREA NAME=Problem ROWS=17 COLS=70></TEXTAREA></td></tr>";
echo "<tr><td align=left>Date : <td align=left><input type=text NAME=callDate value='$callDate'></td></tr>";   
echo "<tr><td align=left>Time : <td align=left><input type=text NAME=callTime value='$callTime'></td></tr>";
echo "<tr><td><input type=submit value=Submit><td><input type=reset name=Reset value=Reset></td></tr>";
echo "</form>";
echo "</tr></table>";
?>

 

Things to change:

 

<your data> = this should be everything you want pulling from your table

<your table> = the table you want your data to be pulled from

<your criteria> = What you want the data to be eg "where account_id='1'"

<your row name> = in your case i think it is SiteName not sure.

 

but i think this might work, it is how i would of done it anyway. Also note how i removed the </td></tr> from the end of <select NAME=SiteName1> that caused a problem too. Hope this helps anyway.

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.