【发布时间】:2016-06-04 06:16:24
【问题描述】:
我想使用 GET 方法通过我的地址栏检查用户是否存在。如果该用户存在,则回显 $username 和 $firstname。但它显示 2 个错误。不知道怎么回事!
<?php include ("./trial/header.php"); ?>
<?php
//we want to perform http://localhost/test.php?=jude to see if user exists then displays username and first name
//the table name is users and include username, first_name, last_name, password and email.
if (isset($_GET['u'])) {
$username = mysqli_real_escape_string($con, $_GET['u']);
if (ctype_alnum($username)) {
//check if user exists
$check = mysqli_query($con, "SELECT username, first_name FROM users WHERE username='$username'");
//if user exists we want to display username and firstname on the page
if (mysqli_num_rows($check)===1) {
$get = mysqli_fetch_assoc($check);
$username = $get['username'];
$firstname = $get['firstname'];
}
//if user do not exist we want to to display "The user does not exist"
else
{
echo "The user does not exist"; //no existing users
exit();
}
}
}
?>
<h2>Profile page for: <?php echo $username;?></h2>;
<h2>First name: <?php echo $firstname;?></h2>;
【问题讨论】:
-
firstname不等于first_name -
http://localhost/test.php?=jude将是http://localhost/test.php?u=jude -
把`$username=""; $名 = ""; `就在
if (isset($_GET['u'])) {之前,看看错误是否消失了?我认为您的代码没有输入您的if statement... -
@PraveenKumar 这就是答案,你应该发布它。