简体   繁体   中英

No result from options selected from a database column (php-mysql)

In the PHP code below i want to select all the column values of a table and make them options of a select form. The result is that i dont get any options at all. Could someone help? Thanks

<?php
// ....

$userid=$_SESSION['userid'];
echo "<select>";
$sql = "SELECT * FROM users where userid='".$userid."'";

$result = mysql_query($sql);

while($row = mysql_fetch_array($result))
{
 echo "<option>" .$row['company']. "</option>";
}
echo "</select>";

mysqli_close();
?>

It may just be a typo but you have mixed mysql and mysqli functions, you have stated mysql_query and mysql_fetch_array, whereas you have closed it with mysqli_close, could be an issue depending on what you wrote above this code or indeed if this is not just a typo.

Other things to try would be try the query in your mysql client / phpmyadmin and see if it comes up with any results or errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM