3

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..

6
  • This means that the file does not get interpreted as PHP code. So the question is: how do you open it? Commented Jul 1, 2015 at 6:33
  • Show a screenshot of what you actually see. Commented Jul 1, 2015 at 6:33
  • And what about this echo "1";? This probably generates invalid HTML, right? Commented Jul 1, 2015 at 6:34
  • @JimGarrison The OP clearly said what he sees. Commented Jul 1, 2015 at 6:34
  • 2
    did you save file as .php, and did you run it from server Commented Jul 1, 2015 at 6:35

4 Answers 4

2

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...

Sign up to request clarification or add additional context in comments.

Comments

2

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

  • you have set file type to php (.php),
  • your server is running and have php support
  • your file is not outside of server folder

1 Comment

Add also - "You are running website trough webserver, not by opening file directly in browser" :)
0

Try after remove var_dump and echo "1" from your php code hope this helps.

Comments

0

Try this. Assumption is you are fetching the 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>

1 Comment

echo "1"; still needs to be removed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.