有人可以帮助以下查询。下面提到的代码不返回FirstName和LastName。为什么呢?
干杯, Akhil G
<?php
$username = mysql_real_escape_string($_GET['user']);
$firstname ="" ;
$lastname ="";
if (ctype_alnum($username))
{
//check user exist
$check = mysql_query("SELECT username, first_name, last_name FROM syn where username = '$username'");
if (mysql_num_rows($check) === 1)
{
$get = mysql_fetch_array($check);
$username = $get['username'];
$firstname = $get['first_name'];
$lastname = $get['last_name'];
} else
echo "<h2> User Does Not Exist ! </h2>";
exit();
}
?>
答案 0 :(得分:0)
您使用了错误的获取功能
$get = mysql_fetch_array($check);
将数据存储在数组中的编号位置,因此返回的数据存储在$ get [0],$ get [1]和$ get [2]中。
您可以使用print_r($ get);
查看内容改为使用
$get = mysql_fetch_assoc($check);
将数据存储在您需要的关联数组中。
答案 1 :(得分:0)
试试这个..
<?php
$username = mysql_real_escape_string($_GET['user']);
$firstname ="" ;
$lastname ="";
if (ctype_alnum($username))
{
//check user exist
$check = mysql_query("SELECT username, first_name, last_name FROM syn where username = '$username'");
if (!$check)
{
$get = mysql_fetch_row($check);
$username = $get[0];
$firstname = $get[1];
$lastname = $get[2];
} else
echo "<h2> User Does Not Exist ! </h2>";
exit();
}
?>
答案 2 :(得分:0)
谢谢大家..但似乎我运气不好..似乎没有工作..尝试了所有选项建议..下面是修改后的版本,再次没有打印名字姓氏或用户名
<?php
include("./inc/header.inc.php");
?>
<?php
if (isset($_GET['user']))
{
$username = mysql_real_escape_string($_GET['user']);
$firstname ="" ;
$lastname ="";
if (ctype_alnum($username))
{
//check user exist
$check = mysql_query("SELECT username, first_name, last_name FROM syn where username = '$username'");
if (mysql_num_rows($check) === 1)
{
$get = mysql_fetch_assoc($check);
$username = $get['username'];
$firstname = $get['first_name'];
$lastname = $get['last_name'];
} else
echo "<meta http-equiv =\"refresh\" content=\"0; url = http://localhost:8080/FirstTry/Tests/index.php\">";
exit();
}
}
?>
<div class="postForm" > Post form will go in here .. </div>
<div class="postPosts" > Your Post will go in here ..</div>
<img src ="" height="250" width="200" alt ="<?php echo $firstname; ?>'s profile" title="<? echo $firstname; ?>'s profile"/>