Jump to content

Navigating database results and posting new values


zemax

Recommended Posts

I am trying to dynamically display results that I retrieve from my database i.e. only 5 results per page and code should automatically compute how many pages it needs and create links for each page. I have also added a link at the top of my page so that if user wants to POST new data he can post it. Problem is that when I click on page 2 or 3 or any numbered page and click on POST link it gives me following error

"CGI Error

The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

 

And it did not tell about any header etc. I have pasted my code below. Please guide me. Thanks

 


<head>
<h2>POST</h2>
<a href="post.php"><b><font size="4">Post!!</font></b></a>
</head>

<?php

if(!isset($_GET['page'])){ 
    $page = 1; 
} else { 
    $page = $_GET['page']; 
} 

// Define the number of results per page 
$max_results = 5; 

// Figure out the limit for the query based 
// on the current page number. 
$from = (($page * $max_results) - $max_results);  

// Perform MySQL query on only the current page number's results 

$sql = mysql_query("SELECT * FROM MYDB LIMIT $from, $max_results"); 

while($row = mysql_fetch_array($sql)){ 

echo "<hr>";

   	echo "<b><font color='#660000' size='4'>".$row['NAME']."</font></b>";
echo "<br>\n";
    
    } 

// Figure out the total number of results in DB: 
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM MYDB"),0); 

$total_pages = ceil($total_results / $max_results); 

// Build Page Number Hyperlinks 
echo "<hr><center>Select Page<br />"; 

// Build Previous Link 
if($page > 1){ 
    $prev = ($page - 1); 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> "; 
} 

for($i = 1; $i <= $total_pages; $i++){ 
    if(($page) == $i){ 
        echo "$i "; 
        } else { 
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; 
    } 
} 

// Build Next Link 
if($page < $total_pages){ 
    $next = ($page + 1); 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>"; 
} 
echo "</center>"; 
?> 

If it didn't list any headers then that's probably your problem right there.

Browsers require headers from the server.

 

Sorry I am a new programmer. What kind of headers do I need to send to server? can you guide me or point me to some place where I can read about it and see examples?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.