[SOLVED] View.php?id=x show it....

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

[SOLVED] View.php?id=x show it....

Post by Dale »

ok i've just been making a small guestbook script thing and i've done a basic template for the front page and inserted data via mysql. It works:
http://www.tcwonline.org/~dale/guestbook/

Now the view link wont work though. Now how would i do this:

Go here:
http://www.blah.com/view.php?id=1
... and it shows me what ever the database has as ID 1?

Im connecting and reading info using this:

Code: Select all

<?
mysql_pconnect("localhost","username","password");
mysql_select_db("db");
$result = mysql_query("select * from guestbook");
while($r=mysql_fetch_array($result))
&#123;	
	$id=$r&#1111;"id"];
	$title=$r&#1111;"title"];
	$msg=$r&#1111;"msg"];
	$author=$r&#1111;"author"];
	$email=$r&#1111;"email"];
	$date=$r&#1111;"date"];
	echo "WHATEVER I WANNA ECHO";
&#125;
?>
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Code: Select all

<?php
$id = trim($_REQUEST['id']); // REQUEST so you can still grab the id from a POST form
mysql_pconnect("localhost","username","password") or die(mysql_error()); 
mysql_select_db("db") or die(mysql_error()); 
$result = mysql_query("select * from guestbook where id='$id'") or die(mysql_error()); // added:  where id='$id'
while($r=mysql_fetch_array($result)) 
{    
   $id=$r["id"]; 
   $title=$r["title"]; 
   $msg=$r["msg"]; 
   $author=$r["author"]; 
   $email=$r["email"]; 
   $date=$r["date"]; 
   echo "WHATEVER I WANNA ECHO"; 
}
?>
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

Thank you very much ;) Its now working :)
Post Reply