gpt4 book ai didi

php - $_GET 变量在分页代码中未定义

转载 作者:行者123 更新时间:2023-11-29 13:23:24 25 4
gpt4 key购买 nike

我不熟悉 PHP,并且在如何在分页代码中创建 $_GET$_SESSION 变量方面遇到了 2 周的问题。情况是:

我从 index.php 页面获得一个值,当我单击它(例如照片/图像)时,我使用 GET 获取该值,然后当我将该值回显到我的 Category 时.php 页面,该值使用“echo”在我的 BODY 页面中投影正常,但我想要的是当页面加载时,GET 变量将是我的分页代码中的搜索键。但是,当我在分页代码中回显 GET 变量时,我得到的结果是“UNDEFINED”,这意味着该变量未在我的分页代码中定义。这是我的分页。哦,是的,我对我的代码进行了更改,我很抱歉,但这是我使用 $mycat 和 GET 方法的先前代码。对不起。

<?php
session_start();
$mycat =$_GET['category'];
//PHP code for specific search
$action = (isset($_REQUEST['action'])&& $_REQUEST['action'] !=NULL)?$_REQUEST['action']:'';

if($action == 'ajax'){

/* Connect To Database*/
$dbname = 'ufile';
$link = mysql_connect("localhost","root","") or die("Couldn't make connection.");
$db = mysql_select_db($dbname, $link) or die("Couldn't select database");

$mycat = htmlspecialchars ($_GET['category']) ? trim($_GET['category']) : ''; //SQL injection protection

include 'pagination.php'; //include pagination file

//pagination variables
$page = (isset($_REQUEST['page']) && !empty($_REQUEST['page']))?$_REQUEST['page']:1;
$per_page = 10; //how many records you want to show
$adjacents = 4; //gap between pages after number of adjacents
$offset = ($page - 1) * $per_page;

echo 'Result: ' .$mycat; //////////THIS IS THE GET VALUE....WHICH TURNS OUT AS UNDEFINED IN VALUE IT SHOULD BE 'PHOTOS/IMAGES, AUDIOS/VIDEOS or COMPRESSED FILES'....PLEASE HELP ME.

//Count the total number of row in your table*/
$count_query = mysql_query("SELECT COUNT(category) AS numrows FROM udocs WHERE category LIKE '%" . $mycat . "%'"); //Count the number of search result here (tagal kitang hinanap dito ka lng pala)
$row = mysql_fetch_array($count_query);
$numrows = $row['numrows'];
$total_pages = ceil($numrows/$per_page);
$reload = 'cat_index.php';

//main query to fetch the data
$result = mysql_query("SELECT * FROM udocs WHERE category LIKE '%" . $mycat . "%' ORDER BY date_upload LIMIT $offset,$per_page");


//loop through fetched data
while($test = mysql_fetch_array($result)){

$id = $test['file_name'];
$fileid=$test['file_path'];

echo "<div class='content'>";
echo'<div class="img_content" ><img src='.$test['file_icon'].' style=height:50px;width:50px;float:left;margin-right:10px;></div>';
echo"<font color='black'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>Name: </font><font color='yellowgreen'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>" .$test['file_name']."</font><br>";
echo"<font color='black'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>Category: </font><font color='gray'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>" .$test['category']."</font></font><font color='skyblue'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';> | </font><font color='black'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>Size: </font><font color='gray'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>" .$test['file_size']."</font></font><font color='skyblue'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';> | </font><font color='black'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>Credits to: </font><font color='gray'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>" .$test['author']."</font><font color='skyblue'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';> | </font><font color='black'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>Date Uploaded: </font><font color='gray'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>" .$test['date_upload']."</font><br>";
echo"<font color='black'; font size='2px !important' ;>Description:". $test['description']. "</font><br>";
echo"<a href ='download.php?file_path=$fileid' ><font color='orange' title='$mycat'>Download File</p></a>";
echo "</div>";

}
//BOTTOM
if ($numrows==0)
{

}
else
{
echo paginate($reload, $page, $total_pages, $adjacents);
}

//header('Location:index.php');
//die();

} // end of ajax first condition
else
{

?>
<body>

<?php
echo 'You are searching for: '.$mycat;
?>

</body>

<?php } ?>

最佳答案

如果 $_REQUEST 允许您访问参数,但 $_GET 不允许,请尝试 $_POST,这意味着使用的 HTTP 方法是 POST 而不是 GET。还要检查提交到此脚本的表单/javascript。 $_REQUEST 是一个包罗万象的超全局变量,包含 get 和 post 参数(还有 cookies!)。

$_REQUEST

我还建议深入阅读一下 HTTP 协议(protocol),它可以帮助解决此类问题:)

除了 Joren 刚刚评论的内容之外,请务必添加您用于访问此页面的 URL。

关于php - $_GET 变量在分页代码中未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20461928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com