1
我想显示一个变量从php我从一个mySQLi服务器获得。但是,它只显示一个空字符串作为'名称'变量。PHP变量不在页面上显示
我的代码是:
$GLOBALS[name] = "";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("<br>Connection failed: " . $conn->connect_error);
$out = "Error when connecting to the database.";
} else {
echo "<br>Connected successfully";
$sql = "SELECT name, pwd FROM server1.us WHERE UPPER(eml) = UPPER('$email')";
$result = $conn->query($sql);
$pwdHash = "";
if ($result->num_rows == 0) {
$out = "Your email is not registered yet.";
}
else {
while($row = $result->fetch_assoc()) {
$pwdHash = $row['pwd'];
}
}
if (password_verify($pwd, $pwdHash) == false) {
$out = "Your passwords do not match!";
}
else if($email == '') {
$out = "You have to input an email.";
}
else if($pwd == '') {
$out = "You have to input a password.";
}
else {
while($row = $result->fetch_assoc()) {
$name = $row['name'];
}
}
$conn->close();
我的代码显示该值:
<?php
if($out == null) {
echo "<h3>Thank you for logging in, $name!</h3>";
echo "<p>You will be redirected...</p>";
} else {
echo "<h3>Oops! Apparently something went wrong...</h3>";
echo "<p>$out</p>";
echo "<p>You can try again <a data-toggle='modal' data-target='#loginModal'>here</a> .</p>";
}
?>
执行时,没有错误,而只输出
谢谢你在登录, ''! 您将被重定向...
我的数据库表中已列如下:
id
name
eml
pwd
使用全局引发内部服务器错误。另外,您在 $ row = $ result-> fetch_assoc();中缺少分号。 如果我没有弄错。 –