我有一个网络论坛,只允许一些选定的用户访问它,即他们必须$_SEESION['username']
开启。
现在在个人资料页面上 - 看起来像这样
http://127.0.0.1/mysite/profile.php?username=john
我想显示上传按钮或编辑个人资料按钮, 取决于他们是否上传了图片。
我正在检查$ _GET是否已设置,如果不是,则重定向到 主页:
if(isset($_GET['username'])) {
$username = mysql_real_escape_string($_GET['username']);
$profile = mysql_query(SELECT *
FROM forum
WHERE username = '$username') or DIE(mysql_error());
$row = mysql_fetch_array($profile);
echo"
Name : $row[name];
Country : $row[country];
if($_GET['username'] == $_SESSION['username'] && $row['imagepath'] == '') {
echo "Upload Button";
}
else {
echo"Edit Button";
}
}
上传按钮显示在屏幕上,实际上有一个图像 路径指定。
请问我哪里出错了。
答案 0 :(得分:1)
你应该在你的mysql_query参数周围添加双引号。我复制了你的代码,这是我的解决方案。
顺便说一句,你的回音太多了。它应该如下面的代码。
echo "Name: ".$row['name'];
echo "Country: ".$row['country'];
if($_GET['username'] == $_SESSION['username'] && $row['imagepath'] == '') {
echo "Upload Button";
}
else {
echo"Edit Button";
}
答案 1 :(得分:0)
mysql_query("QUERY HERE")
,否则根本不起作用。$row['name']
,$row['country']
:您需要在引号之间加上名称。echo 'Text'
。你没有关闭引号。empty($row['imagepath'])
。它有一个功能,所以使用它。如果上述更正仍无效,请尝试回显所需的所有变量:$_GET['username']
,$_POST['username']
,$row['imagepath']
。也许PHP无法读取它们。
答案 2 :(得分:-1)
修复了从这里开始调试的所有语法错误:
if ( isset( $_GET['username'] ) ) {
$username = mysql_real_escape_string( $_GET['username'] );
$profile = mysql_query( "SELECT *
FROM forum
WHERE username = '$username'" ) or DIE( mysql_error() );
$row = mysql_fetch_array( $profile );
echo "Name : " . $row['name'];
echo "Country : ". $row['country'];
if ( $_GET['username'] == $_SESSION['username'] && $row['imagepath'] == '' ) {
echo "Upload Button";
}
else {
echo"Edit Button";
}
}