Page 1 of 1

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

Posted: Fri Dec 19, 2003 9:29 pm
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;
?>

Posted: Fri Dec 19, 2003 10:56 pm
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"; 
}
?>

Posted: Sat Dec 20, 2003 8:34 pm
by Dale
Thank you very much ;) Its now working :)