PDA

View Full Version : Need help with passing values in URL using PHP & MySQL



Adamwlad
01-23-2004, 03:48 PM
I have a MySQL database with:

id
username
address
phone

How can I have a simple link i.e.


<a href="something.php?id=1&uername=john">
link</a>

and have a PHP page showing the values for John's address and phone

Can somebody help? I would really appreciate it.

Thanks,
-Adam

Adamwlad
01-26-2004, 12:53 PM
I figured out my own problem. For anyone else who needs this, here's what I figured out.

One page has the link:


Link (http://www.somewhere.com/page2.php?id=1)


Second page (page2.php):


<?php
$id=$_GET['id'];
?>

<?php

$dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("database");

$query="SELECT * FROM table WHERE id='$id'";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();


$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$name=mysql_result($result,$i,"name");
$phone=mysql_result($result,$i,"phone");

echo "$name
$phone";

++$i;
}

?>
[/code]