Why is my php script not dynamically populating an input field on my html form? -


i building html form need dynamically fill in first input field "facility" column values in "doctors" table. facility column contains names of our 7 offices. however, when run code below, input field blank , have verified there data in "doctors" table. after working, need able dynamically fill in second input field (which haven't coded in code below because i'm stuck issue of first input) "provider" column values, "doctors" table. "provider" column contains provider names in our practice. however, providers should filtered, providers @ facility first input field showing.

<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html>   <?php      $link = mysqli_connect("localhost","username","password");      mysqli_select_db($link,"db");   ?>   <head>     <title> untitled doc</title>     <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">   </head>   <body>     <form name "form1" action="" method="post">       <select>         <?php         $res=mysqli_query($link,"select facility doctors");         while($row=mysqli_fetch_array($res)){?>           <option> <?php echo $row ["facility"]; ?></option>         <?php }?>       </select>     </form>   </body> </html> 

it important check if connection have been established, have copied code , use on side , working fine, therefore made me suspect problem might connection related. check how sensitive server maybe server see error : $row ["facility"] space might problem well, didn't on side.

check server error log , enable error reporting @ top of page add

<?php  ini_set('display_errors', 1);  error_reporting(e_all);?> 

that enable error reporting, use on local server only

then on live site send them error log

error_reporting(e_all); ini_set('display_errors',0); ini_set('log_errors',1); 

also mysqli errors, before connection

mysqli_report(mysqli_report_error | mysqli_report_strict);

important check if query indeed return results before trying display them.

<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">     <html>     <?php      $link = mysqli_connect("localhost", "root", "", "db");         if (mysqli_connect_errno()) {             printf("connect failed: %s\n", mysqli_connect_error());             exit();         }     ?>     <head>     <title> untitled doc</title>     <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">     </head>     <body>     <form name ="form1" action="" method="post">     <?php        $query = "select facility doctors";          if ($res = mysqli_query($link, $query)) {             echo "<select name=\"myselect\">";             while ($row = mysqli_fetch_assoc($res)) {         ?>          <option value="<?php echo $row['facility'];?>"><?php echo $row['facility'];?></option>            <?php             }              echo "</select>";             mysqli_free_result($res);         } else {              printf("error : %s\n", mysqli_error($link));         }          /* close connection */         mysqli_close($link);         ?>        </form>     </body>     </html> 

nb: own benefit, if haven't used prepared statements, suggest learn them well, though not needed in case


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -