Jump to content

Archived

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

genista

Passing details to another page

Recommended Posts

Hi all,

I have a search form that a user submits. The results come back with the ability to click on them and look at the search result details in a supplierdetails.php page.

I have the following query to match the page to the search results, but am having problems deciding how to use the query to display the details of the supplier. The query goes like such:

$id = $_GET['id'];
$query = "select * from suppliers where id=$username";

Has anybody got any examples I could look at to get an idea?


Thanks

G

Share this post


Link to post
Share on other sites
$id = $_GET['id'];
$query = "select * from suppliers where id='$id'";

maybe you should clarify your question with more details.

Share this post


Link to post
Share on other sites
Ok well the id will be supplierid as this is called from the suppliers table. The problem as you well know is that the query won't display anything, but I am interested in knowing they wain which to display the details of the supplier on the page.

Does that help?

Share this post


Link to post
Share on other sites
so you got the query set up.

you'll need to connect to mysql server, select database, execute the query, retrieve results and display the data.

Refer to mysql function reference in PHP manuals, it has everything you needed.

Share this post


Link to post
Share on other sites
After you do the query, you have to use one of the mysql_fetch functions to actually get the data so you can display it. In it's simplest form this would be:
[code]<?php
$id = $_GET['id'];
$query = "select * from suppliers where id='" . mysql_real_escape_string($id) . "'";
$rs = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());
while ($rw = mysql_fetch_assoc($rs))
    echo '<pre>' . print_r($rw,true) . '</pre>';
?>[/code]

I use the function mysql_real_escape_string() to prevent sql injections.

Ken

Share this post


Link to post
Share on other sites

×

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.