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 to share
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 to share