/    Sign up×
Community /Pin to ProfileBookmark

Why Html Form Mr Invisile ?

This was working efore I added session_id() stuffs to neaten things up a it.
Now, it’s not working. Pagination it is.
Prolem is, the html form doesn’t show up
Why is that ?
Sorry, my keyoard is not typing some chars.

[code]
<?php
require ‘conn.php’;
require ‘error_reporting.php’;
?>

<!DOCTYPE HTML”>
<html>

<head>
<meta name=”viewport” content=”width-device=width, initial-scale=1″>
</head>
<body>

<?php

//session_destroy();
session_start();

//if($_SERVER[‘REQUEST_METHOD’] === ‘GET’)
//{
if(ISSET($_GET[‘search’]))//THERE WILL BE MORE THAN ONE BUTTON ON THIS PAGE. HENCE THIS LINE.
{
if(session_id() == NULL)// OR $_SESSION[‘search’] != ‘pagination’) //IT MEANS SESSION NOT RUNNING. DUE TO ‘SEARCH’ BUTTON NOT CLICKED YET.
{
if(ISSET($_GET[‘keywords’]))
{
$keywords = $_GET[‘keywords’];
//$SESSION[‘keywords’] = $keywords;
}
$_SESSION[‘search’] = ‘running’;

echo __LINE__; echo “<br>”;//THIS IS LINE 24
$query_1 = “SELECT COUNT(id) FROM links WHERE keywords = ? OR keyphrases = ?”;
$stmt_1 = mysqli_stmt_init($conn);
if(mysqli_stmt_prepare($stmt_1,$query_1))
{
mysqli_stmt_bind_param($stmt_1,”ss”,$keywords,$keywords);
mysqli_stmt_execute($stmt_1);
$result_1 = mysqli_stmt_bind_result($stmt_1,$row_count);
$SESSION[‘row_count’] = $row_count;

if($bind_result_1 === FALSE)
{
echo __LINE__;echo “<br>”;
printf(“Error: %s.n”, mysqli_stmt_error($stmt));
printf(“Error: %d.n”, mysqli_stmt_errno($stmt));
die;
}

mysqli_stmt_fetch($stmt_1);
echo “Row Count:”; echo $_SESSION[‘row_count’]; echo “<br>”;
}
else
{
echo __LINE__;echo “<br>”;
die(“prepare failed!”);
}
mysqli_stmt_close($stmt_1);
//mysqli_close($conn);//THIS LINE CAUSED THE WHOLE PAGINATION TO MALFUNCTION GIVING FALSE ERROR PREPARE FAILED!

//PAGINATION STARTS FROM HERE
if(!ISSET($_GET[‘page’]))
{
$page = 1;
}
else
{
$page = $_GET[‘page’];
}

if(!ISSET($_GET[‘limit’]))
{
$limit = 2;
$SESSION[‘limit’] = $limit;
}
else
{
$limit = $_GET[‘limit’];
$SESSION[‘limit’] = $limit;
}
echo “Page: $page”; echo “<br>”;
echo “Limit:”; echo $SESSION[‘limit’]; echo “<br>”;

$offset = (($page * $limit) – $limit);
$SESSION[‘offset’] = $offset;

$previous_page = $page-1;
$SESSION[‘previous_page’] = $previous_page;

$next_page = $page+1;
$SESSION[‘next_page’] = $next_page;

echo “Row Start: $offset”; echo “<br>”;
echo __LINE__; echo “<br>”; //THIS IS LINE 78
$query_2 = “SELECT id,page_url,link_anchor_text,page_description,keyphrases,keywords FROM links WHERE keywords = ? OR keyphrases = ? ORDER by id LIMIT $offset,$limit”;
$stmt_2 = mysqli_stmt_init($conn);
if(mysqli_stmt_prepare($stmt_2,$query_2))//WHY PREPARE FAILING ON THIS LINE ?
{
mysqli_stmt_bind_param($stmt_2,”ss”,$keywords,$keywords);
//mysqli_stmt_execute($stmt_2);

if(mysqli_stmt_execute($stmt_2) === FALSE)
{
echo __LINE__;echo “<br>”;
printf(“Error: %s.n”, mysqli_stmt_error($stmt_2));
printf(“Error: %d.n”, mysqli_stmt_errno($stmt_2));
die;
}

$result_2 = mysqli_stmt_get_result($stmt_2);
//Grab total number of pages to paginate.
//$total_pages = ceil($result_1/$limit); //SHOULD I KEEP THIS LINE OR THE ONE BELOW THIS ONE ?
$total_pages = ceil($row_count/$limit); //SHOULD I KEEP THIS LINE OR THE ONE ABOVE THIS ONE ?

echo “TOTAL PAGES: $total_pages<br><br>”;
if(!$result_2)
{
die(“fetching Error”);
}
while($row = mysqli_fetch_array($result_2,MYSQLI_ASSOC))
{
//Retrieve Values.
echo __LINE__;echo “<br>”;
$id = $row[“id”];
$page_url = $row[“page_url”];
$link_anchor_text = $row[“link_anchor_text”];
$page_description = $row[“page_description”];
$keyphrases= $row[“keyphrases”];
$keywords = $row[“keywords”];

echo “Id: $id<br>”;
echo “Page Url: $page_url<br>”;
echo “Link Anchor Text: $link_anchor_text<br>”;
echo “Page Description: $page_description<br>”;
echo “Keyphrases: $keyphrases<br>”;
echo “Keywords: $keywords<br>”;
echo “<br>”;
echo “<br>”;
}
}
else
{
echo __LINE__;echo “<br>”; //THIS IS LINE 127
printf(“Error: %s.n”, mysqli_stmt_error($stmt_2));
printf(“Error: %d.n”, mysqli_stmt_errno($stmt_2));
die(“Prepare failed!”);
}
//Close Statement.
mysqli_stmt_close($stmt_2);

if($page_number>$total_pages)
{
echo “?><a href=”pagination_test.php?limit=$limit&page=$total_pages”>”;?><?php echo “<b> Final Page </b>”;?></a><?php
}
else
{
$i = 1;
while($i<=$total_pages)
{
if($i<$total_pages)
{
echo “<a href=”pagination_test.php?limit=$limit&page=$i”>”;?><?php echo ” $i “;?></a><?php
}
elseif($i==$page_number)
{
echo “<a href=”pagination_test.php?limit=$limit&page=$i”>”;?><?php echo “<b> $i </b>”;?></a><?php
}

$i++;
}
}
$_SESSION[‘search’] = ‘pagination’;
}
}

if(session_id() != NULL && $_SESSION[‘search’] == ‘pagination’) //IT MEANS SESSION IS RUNNING. DUE TO ‘SEARCH’ BUTTON CLICKED.
{
echo session_id(); //DEV MODE LINE
echo “<br>”;//DEV MODE LINE
echo __LINE__;//DEV MODE LINE
echo “<br>”;//DEV MODE LINE

if(ISSET($_GET[‘page’]))
//PAGINATION COPY STARTS FROM HERE. THE COPY THAT WILL RUN WHEN PAGE 2 AND ONWARDS ARE LOADED INDEPENDANT OF THE ‘SEARCH’ BUTTON CLICK.
if(ISSET($_GET[‘page’]))
{
$page = $_GET[‘page’];
}

if(!ISSET($_GET[‘limit’]))
{
$SESSION[‘limit’];
}
else
{
$limit = $_GET[‘limit’];
}
echo “Page: $page”; echo “<br>”;
echo “Limit:”; echo $SESSION[‘limit’]; echo “<br>”;

$offset = (($page * $limit) – $limit);
//$SESSION[‘offset’] = $offset;

$SESSION[‘previous_page’] = $previous_page;

$SESSION[‘next_page’] = $next_page;

echo “Row Start: $offset”; echo “<br>”;
echo __LINE__; echo “<br>”; //THIS IS LINE 78
$query_2 = “SELECT id,page_url,link_anchor_text,page_description,keyphrases,keywords FROM links WHERE keywords = ? OR keyphrases = ? ORDER by id LIMIT $offset,$limit”;
$stmt_2 = mysqli_stmt_init($conn);
if(mysqli_stmt_prepare($stmt_2,$query_2))//WHY PREPARE FAILING ON THIS LINE ?
{
mysqli_stmt_bind_param($stmt_2,”ss”,$_GET[‘keywords’],$_GET[‘keywords’]);
//mysqli_stmt_execute($stmt_2);

if(mysqli_stmt_execute($stmt_2) === FALSE)
{
echo __LINE__;echo “<br>”;
printf(“Error: %s.n”, mysqli_stmt_error($stmt_2));
printf(“Error: %d.n”, mysqli_stmt_errno($stmt_2));
die;
}

$result_2 = mysqli_stmt_get_result($stmt_2);
//Grab total number of pages to paginate.
//$total_pages = ceil($result_1/$limit); //SHOULD I KEEP THIS LINE OR THE ONE BELOW THIS ONE ?
$total_pages = ceil($_SESSION[‘row_count’]/$limit); //SHOULD I KEEP THIS LINE OR THE ONE ABOVE THIS ONE ?

echo “TOTAL PAGES: $total_pages<br><br>”;
if(!$result_2)
{
die(“fetching Error”);
}
while($row = mysqli_fetch_array($result_2,MYSQLI_ASSOC))
{
//Retrieve Values.
echo __LINE__;echo “<br>”;
$id = $row[“id”];
$page_url = $row[“page_url”];
$link_anchor_text = $row[“link_anchor_text”];
$page_description = $row[“page_description”];
$keyphrases= $row[“keyphrases”];
$keywords = $row[“keywords”];

echo “Id: $id<br>”;
echo “Page Url: $page_url<br>”;
echo “Link Anchor Text: $link_anchor_text<br>”;
echo “Page Description: $page_description<br>”;
echo “Keyphrases: $keyphrases<br>”;
echo “Keywords: $keywords<br>”;
echo “<br>”;
echo “<br>”;
}
}
else
{
echo __LINE__;echo “<br>”; //THIS IS LINE 127
printf(“Error: %s.n”, mysqli_stmt_error($stmt_2));
printf(“Error: %d.n”, mysqli_stmt_errno($stmt_2));
die(“Prepare failed!”);
}
//Close Statement.
mysqli_stmt_close($stmt_2);

if($page>$total_pages)
{
echo “?><a href=”pagination_test.php?limit=$limit&page=$total_pages”>”;?><?php echo “<b> Final Page </b>”;?></a><?php
}
else
{
$i = 1;
while($i<=$total_pages)
{
if($i<$total_pages)
{
UNSET($_SESSION[‘search’]);
echo “<a href=”pagination_test.php?limit=$limit&page=$i”>”;?><?php echo ” $i “;?></a><?php
}
elseif($i==$page)
{
echo “<a href=”pagination_test.php?limit=$limit&page=$i”>”;?><?php echo “<b> $i </b>”;?></a><?php
}

$i++;
}
}
}
//Close Connection.
//mysqli_close($conn);
//PAGINATION COPY ENDS HERE

?>

<form method=’GET’ action=”<?php echo $_SERVER[‘PHP_SELF’];?>?limit=$limit&page=$page”>
<label for=”keywords”>Keywords:*</label>
<input type=”text” name=”keywords” id=”keywords” placeholder=”Input Keywords” required>
<br>
<label for=”limit”>Results per Page</label>
<select name=”limit” id=”limit”>
<option value=”10″>10</option>
<option value=”10″>25</option>
<option value=”10″>50</option>
<option value=”10″>100</option>
</select>
<br>
<button name=search value=” “>Search</button><br>
<button type=”submit” name=”search” value=”search”>Search</button>
<br>
<input type=”reset”>
<br>
</form>
[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...