Jump to content


Photo

Passing details to another page


  • Please log in to reply
4 replies to this topic

#1 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 14 July 2006 - 01:35 PM

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

#2 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 14 July 2006 - 01:42 PM

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

maybe you should clarify your question with more details.

Life's too short for arguing.

#3 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 14 July 2006 - 01:52 PM

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?

#4 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 14 July 2006 - 02:06 PM

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.
Life's too short for arguing.

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 14 July 2006 - 02:07 PM

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:
<?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>';
?>

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

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users