Page 1 of 1

A better way???

Posted: Sun Sep 21, 2003 7:45 pm
by 3.14
I'm trying to make a button to navigate from one record to the next. So essentially I'll have previous, next, first and last. Now I thought I was on to something with the following code...

Code: Select all

<?php
<p align=center><a href="<?= $query = "SELECT * FROM tblEmployee WHERE EmployeeID=2"; // get second record
    $result = mysql_query($query) or die("Query failed : " . mysql_error()); ?>">Next Record</a></p>
?>
But... I got the following once I clicked on the next record link

Forbidden
You don't have permission to access /SELECT * FROM tblEmployee WHERE EmployeeID=2 on this server.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.


--------------------------------------------------------------------------------

Apache/2.0.47 (Win32) PHP/4.3.3 Server at localhost Port 80


What is going wrong? Is there a better way to navigate records in a database?

Posted: Sun Sep 21, 2003 8:24 pm
by volka
please read Frames, JavaScript, and PHP Overview
essentially php runs server-side, i.e. what php is and what it can only exists on the server. On the the other side there is the client, having its own functions/engine (e.g. javascript). Usually they are connected only by a protocol called http.
The client sends a request, the server handles it, sends back a document as reply and the connection is done. The client now parses the document and (hopefully) displays something (like an html page).
When a server-side php-script is involved the document that is sent back is only the output of that php-script
Therefor you cannot invoke a php-function from the client directly.
In your case the client only sees

Code: Select all

<p align=center><a href="SELECT * FROM tblEmployee WHERE EmployeeID=2">Next Record</a></p>
whichis not a correct href ;)

You have to send a new request that the script can handle.
e.g.

Code: Select all

<a href="thescript.php?EmployeeID=2">
the script (which again runs froms the beginning) fetches the paramter and uses it in the query...
maybe you should read some tutorials on that matter
e.g. http://w3.phpfreaks.com/tutorials/73/0.php