Hi I am a newbie to PHP. i am having serious problems trying to pass the id to the next page via a hyperlink. i am creating a real estate website and after searching for a property the code below is displayed. this code basically should list all the properties. the properties should be hyperlinked so when you click it, it displays the full detail. So far the code only displays the name. how would i hyperlink the data with id sent to the next page?

ANY HELP WOULD BE MUCH APRECIATED.

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?
$username="proper_asik112";
$password="ashik112";
$database="proper_contacts";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query('SELECT * FROM contacts
WHERE first=\''. $_POST.'\' And mobile=\''. $_POST.'\'');;


while($row=mysql_fetch_array($result))
{
echo $row . " " . $row . "<br />";
}

?>
</body>
</html>

use this:

$sql = "SELECT * FROM `contacts` WHERE `first1 = '" . $_POST['name'] . "' AND `mobile` = '" . $_POST['mobile'] . "'";
$query = mysql_query($sql);
while ($row = mysql_fetch_assoc($query)) {
  echo '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $row['id'] . '">' . $row['first'] . ' ' . $row['last'] . '</a>';
}

then use $_GET to 'get' the id from the url and select the info from the database related to that id

I will explain you the logic what has to be done with an example and you can implement that in your script.

$results = mysql_query("SELECT * FROM f_category ORDER BY c_order DESC", $connection);
    $numrows = @mysql_num_rows($results);
    $x = 0;
    while ($x < $numrows) {
        $cid = stripslashes(mysql_result($results, $x, "c_id"));
        $cname = stripslashes(mysql_result($results, $x, "c_name"));
        echo "Property Name = <a href=deails.php?cid=$cid>$cname</a>";
        $x++;
        }

Now what this will do is print a list of property names and with their cid's as the hyperlink.
and you can use GET method in details.php to retrieve cid and print the results :)

it comes up with this error

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/proper/public_html/welcome.php on line 19

it comes up with line 19 error
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/proper/public_html/welcome.php on line 19

did you connect to the database first?

did you connect to the database first?

i did connect but it didnt work

i tried this code and it worked. Do u know how i could add image and hyperlink the image aswell

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?
$username="proper_asik112";
$password="ashik112";
$database="proper_contacts";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query('SELECT * FROM contacts
WHERE first=\''. $_POST.'\' And mobile=\''. $_POST.'\'');;


while($row=mysql_fetch_array($result))
{
echo '<a href="' . $_SERVER . '?id=' . $row . '">' . $row . ' ' . $row . '</a>';
}

?>
</body>
</html>

i am typing up some code for you now, ill post asap.

i am typing up some code for you now, ill post asap.

thanks

use all of this code, not pieces of it, or you will get errors.

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php

$host = 'localhost';
$user = 'proper_asik112';
$pass = 'ashik112';
$db   = 'proper_contacts';

$con = mysql_connect($host,$user,$pass) or die('Error: Could not connect');
mysql_select_db($db) or die('Error: Could not select database');

$sql   = "SELECT * FROM `contacts` WHERE `first` = '" . mysql_real_escape_string($_POST['name']) . "' AND `mobile` = '" . mysql_real_escape_string($_POST['mobile']) . "'";
$query = mysql_query($sql, $con);
while ($row = mysql_fetch_assoc($query)) {
	echo '<a href="pagename.php?id=' . $row['id'] . '">' . $row['first'] . ' ' . $row['last'] . '</a><br />';
}

?>
</body>
</table>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.