Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 调用isset时,如何连接或传递此变量?_Php_Html - Fatal编程技术网

Php 调用isset时,如何连接或传递此变量?

Php 调用isset时,如何连接或传递此变量?,php,html,Php,Html,现在我确信你们都能看到这里的错误,我正在检查这个链接是否被点击 if(isset($_GET['action']) && $_GET['action']=='album_id=$album['id']') 并在if语句中返回未定义的变量,表示album是未定义的变量 这是我的htaccess文件: if($_GET['action'] == 'album_id' && $_GET['action_id'] == $album['id']) 这是我的整个php

现在我确信你们都能看到这里的错误,我正在检查这个链接是否被点击

if(isset($_GET['action']) && $_GET['action']=='album_id=$album['id']')
并在if语句中返回未定义的变量,表示album是未定义的变量

这是我的htaccess文件:

if($_GET['action'] == 'album_id' && $_GET['action_id'] == $album['id']) 
这是我的整个php文件:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /lr/profile.php?username=$1 [QSA]

你的页面




正确的方法是对url进行正确编码:

<?php 
include 'core/init.php';
include 'init.image.php';
protect_page();
 include 'includes/overall/overall_header.php';


if(isset($_GET['username']) === true && empty($_GET['username']) === false){
$username       = $_GET['username'];


if(user_exists($username) === true){
$user_id        = user_id_from_username($username);
$profile_data   = user_data($user_id, 'first_name','last_name','email', 'username');
?>

    <h1><?php echo $profile_data['first_name']; ?>'s Yor Page</h1>

<div id="navWrapper">
    <ul>
        <li>
            <a href="#"><img src="uploads/profile/blank_profile.gif" width="150" height="150" id="blank_profile"></a>
        </li>

        <nav>
            <ul>
                <li>
                    <a href="<?php echo $profile_data['username'];?>?action=albums">Albums</a>
                </li>
                <li>
                    <a href="<?php echo $profile_data['username'];?>?action=music">Music</a>
                </li>
            </ul>
        </nav>
    </ul>
</div>

<?php
if(isset($_GET['action']) && $_GET['action']=='albums'){

$albums = get_profile_albums($user_id);

if(empty($albums)){
echo 'No Albums';
}else{
foreach($albums as $album){
if (empty($album['image'])) {

    $album['image'] = 'uploads/profile/blank_profile.gif';
}

?>
 <p><?php echo $album['name'],' (', $album['count'], ')'?> <br />
  <a href="<?php echo $profile_data['username']; ?>?action=album&album_id=<?php echo $album['id']; ?>">
    <img src="uploads/thumbs/<?php echo $album['id'];?>/<?php echo $album['image'];?>" />
  </a><br />
  <?php echo $album['description'];?>...<br />
  </p>
<?php



}


}


}
else if (isset($_GET['action']) && $_GET['action']=='album' && isset($_GET['album_id'])){
echo 'albums';
}







if(isset($_GET['action']) && $_GET['action']=='music'){
echo'<h1>Music</h1>';
}

}else{
    echo 'Sorry, that user doesn\'t exist';
}
}else{
header('Location: index.php');
exit();
}

include 'includes/overall/overall_footer.php';
?>

您没有目标,您尝试访问的php文件在哪里?您从
用户名开始。检查此处
href=“?

试着把动作和id分开,可能只有我一个人,我觉得把它像
action=album=1

你可以这样试试

if(isset($_GET['action']) && urldecode($_GET['action'])=='album_id='.$album['id'])
所以url看起来像

$_GET['action'] == 'album' && $_GET['action_id'] == $album['id']

我想@Dreen回答了你的问题,但我想把action参数分为action和id:

?action=album&action_id=1


你真的可以这样做吗?在url中输入参数,比如
action=album_id=1
?是的,它会返回使用该链接单击的任何专辑的专辑id。感觉有点奇怪,也许我对php还是有点陌生,但我建议另一种方法,我知道它看起来像意大利面代码,我也是新手,遇到的问题比我能处理的要多,但我我下定决心了,如果我知道另一个选择,我会选择它。你能不能也把url重写的输出放在一起,我对重写语法不太在行呢?它抛出一个错误,在if语句中表示未定义的变量album。那么,你希望在if语句中的操作等于什么呢如果取消if检查,则无法将其用于测试
$\u GET['action']
s值…它已定义,我可以在if语句之外将其回显。如果我回显$album['id'];在if语句之外,它返回用户正确的相册id。我将我的htaccess文件添加到问题中,如果它有帮助。我尝试了此操作,但出现了一个错误查看我的问题我编辑了此文件以向您显示是的。url工作正常,并正确返回用户名和相册id,但我无法获得$album['id']出于某种原因,我已经这样做了,以访问此代码所在的用户配置文件页面,现在我正尝试使用链接和获取功能将该用户的图片链接到用户配置文件页面。如果
$album['id']
无法打印,那么您可能想检查是否设置正确。我可以回显if语句,它确实正确回显。我添加了我的htaccess文件,其中是否有必须执行的操作?不,这与if语句中未定义变量相册的错误相同,就像编译器无法识别['id']在变量的末尾,因为错误根本没有提到它。我猜这是来自
$album['id']
的错误。你真的设置了值吗?是的,我可以在if语句之外回显它,它正确地回显。实际上,在url中,它显示它,就像我问题中的链接一样。
if(isset($_GET['action']) && urldecode($_GET['action'])=='album_id='.$album['id'])
$_GET['action'] == 'album' && $_GET['action_id'] == $album['id']
?action=album&action_id=1
<a href="<?php echo $profile_data['username'];?>?action=album&id=<?php echo $album['id'];?>">
if(isset($_GET['action']) && $_GET['action']=='album' && isset($_GET['id']) && $_GET['id']==$album['id'])