PHP code not converting to html

I have php code

<select style="width: 200px;" name="location" id="myselect" onchange="window.location='enable1.php?id='+this.value+'&pos='+this.selectedIndex;">
  <option value="All">All</option>
 <?php

  $sql="select * from location";
  var_dump($sql);
  $query=mysqli_query($conn,$sql);
  echo "1";
  while($row=mysql_fetch_array($query))
  {
      echo "<option value='$row[loc]'>'$row[loc]'</option>";
  }
    ?>

</select>

      

In this code, I echo "options", but instead, when I go through the source code, I see that some of the php is not written in parameters.

+3


source to share


4 answers


You used mysql_fetch_array () instead of mysqli_fetch_array () ... Try this ...

<select style="width: 200px;" name="location" id="myselect" onchange="window.location='enable1.php?id='+this.value+'&pos='+this.selectedIndex;">
<option value="All">All</option>
 <?php

  $sql="select * from location";
  var_dump($sql);
  $query=mysqli_query($conn,$sql);
  echo "1";
  while($row=mysqli_fetch_array($query))
  {
      echo "<option value='$row[loc]'>'$row[loc]'</option>";
  }
    ?>

</select>

      



let me know if it helps ...

+1


source


as Saedawke stated in a comment, when you see PHP code instead of output, it means that this file is not being interpreted as php, but html. Make sure that:



  • you have set the file type to php (.php),
  • your server is up and running php
  • your file is not outside the server folder
+2


source


Try after removing var_dump and echo "1" from your php code, it will help.

0


source


Try it. Let's say you are fetching data.

<select style="width: 200px;" name="location" id="myselect" onchange="window.location='enable1.php?id='+this.value+'&pos='+this.selectedIndex;">
  <option value="All">All</option>
 <?php

  $sql="select * from location";
  var_dump($sql);
  $query=mysqli_query($conn,$sql);
  echo "1";
  while($row=mysql_fetch_array($query))
  {
      echo "<option value=".$row['loc'].">".$row['loc']."</option>"; //added dots
  }
    ?>

</select>

      

0


source







All Articles