Friday 31 August 2018

The php code does not convert to html

I have a 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 of that when I view source code I see php part written not options..

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>

0 comments:

Post a Comment