我试图填充html表单中的下拉字段,但该字段不显示任何值,只有空白。
我在试下面的代码:
--Producto--
require("conectdb.php");
$allproducts = mysql_query("SELECT * FROM Productos");
while ($viewallproducts = mysql_fetch_array($allproducts)){
?>
"><?php echo $viewallproducts["CODIGO"];?>
我改变了引号和;但还是没有,这里是连接到数据库的代码(conectdb.php):
$con=mysqli_connect("localhost","xxxxxx","xxxxxx","xxxxxx");
// Check connection
if (mysqli_connect_errno())
echo "Failed to connect to MySQL: " . mysqli_connect_errno();
mysqli_close($con);
?>这似乎是数据库连接的问题,我现在尝试下面的代码来看看会发生什么:
$username = "xxxxx";
$password = "xxxxx";
$hostname = "xxxx";
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL
";
$allproducts = mysql_query("SELECT * FROM PRODUCTOS");
while ($viewallproducts = mysql_fetch_array($allproducts)){
echo ($viewallproducts);
}
?>但是,在这个PHP,我收到以下错误:
Warning: mysql:fetch_array() expects parameter 1 to be resource.
我也尝试过使用mysql_fetch_row()并给了我同样的错误。