我已经成功启动了Apache,但在我写了一个简单的login.html和login.php之后,我发现我在Mysql数据库中获取了数据。
没有运行时错误,但我使用$result=$conn->query($sql);
获得的对象始终为NULL;
操作系统:Windows 8.1 Wampserver latest version
的login.php
<?php
session_start();
$conn = new mysqli('localhost', 'root', '' , 'mylogin');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM logintable";
$result=$conn->query($sql);
echo "\n".var_dump($result)."\n";
//The problem is the query can't any data, so I delete the following code.
?>
的login.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script language="javascript"type="text/javascript" >
function check(){
var name=LoginForm.username.value;
var pwd=LoginForm.password.value;
if(name==""){
alert("Enter Username");
LoginForm.username.focus();
return (false);
}
if(pwd==""){
alert("Enter Password");
LoginForm.password.focus();
return (false);
}
}
</script>
</head>
<body>
<div class="center">
<form name="LoginForm" method="post" action="login.php" onsubmit="return check(this)">
username:<input name="username" type="text"id="username"/><br />
password:<input name="password" type="password"id="password"/><br/>
<input value="Login" type="submit" name="submit"/>
<input value="register" type="button"onclick="javascrtpt:window.location.href='register.html'"/>
<br/>
</form>
</div>
</body>
</html>
总是打印回声:
object(mysqli_result)[2]
public 'current_field' => null
public 'field_count' => null
public 'lengths' => null
public 'num_rows' => null
public 'type' => null
答案 0 :(得分:0)
现在我可以用这种方式获取数据:
<?php
session_start();
$conn = new mysqli('localhost', 'root', '' , 'mylogin');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM logintable";
if($result=$conn->query($sql))
{
echo "\n".var_dump($result)."\n";
$row = $result->fetch_row();
echo "\n".var_dump($row)."\n";
}
?>
$result
是什么?