我想使用GET方法通过我的地址栏检查用户是否存在。如果该用户存在则echo $ username和$ firstname。但它显示2个错误。我不知道出了什么问题!
UIViewController
答案 0 :(得分:0)
您的if statement
问题您的代码没有输入...
作为一种解决方法,我可以为您提供代码......
<?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.
$username = ""; //Added this
$firstname = "";//Added this
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['first_name'];
}
//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>;
要获得正确的输出,您应该使用此网址http://localhost/test.php?u=jude
代替http://localhost/test.php?=jude
作为Md. Sahadat Hossain
建议。