我正在尝试使用MySQL和PHP创建一个登录系统:
<?php
... irrelevant login code removed ...
session_start();
$con = mysqli_connect("localhost","root","password","test_database");
$result = mysql_query("SELECT firstname FROM users");
echo $result;
?>
但有问题的页面没有显示任何内容。为什么会这样?
谢谢!
答案 0 :(得分:1)
mysql_*
函数与mysqli_*
函数混合使用。 试试这个:
<?php
session_start();
$con = mysqli_connect("localhost","root","password","test_database");
$result = mysqli_query($con, "SELECT firstname FROM users") or die(mysqli_error($con));
while ($row = mysqli_fetch_assoc($result)) {
foreach($row as $key=>$value) {
echo $key.': '.$value."\n";
}
echo "-------------\n";
}
?>