I retrieve three pieces of data from my MySQL table and need to pass one of them as a parameter in a link to a dynamically populated .php page and two of them use as the link text.
The echo statement below is not working.
Could you please see what's wrong with it?
Thank you!

<?php
$connection = mysql_connect("server.com","user","password") or die ("Couldn't connect to server."); 
$db = mysql_select_db("mydb", $connection) or die ("Couldn't select database."); 

$data = "SELECT inventorid, firstname, lastname FROM inventors WHERE taskdate - curdate() = 0";
  $query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());
  
while($data2 = mysql_fetch_array($query)) {
echo "<a href=\"inventorid.php?inventorid=$data2['inventorid']\">$data2['inventorid'] $data2['firstname'] $data2['lastname']</a>\n";
}  
?>

Recommended Answers

All 2 Replies

The echo statement is incorrect.

echo "<a href=\"inventorid.php?inventorid=".$data2['inventorid']."\">".$data2['inventorid']." ".$data2['firstname']." ".$data2['lastname']."</a>\n";

is the correct syntax.
Also, to make life simple, you can use,

$inventorid = $data2['inventorid'];
$firstname = $data2['firstname'];
$lastname = $data2['lastname'];
echo "<a href='inventorid.php?inventorid=$inventorid'>$inventorid $firstname $lastname</a>\n";

Cheers!

It worked.
Thank you! Thank you! Thank you!

The echo statement is incorrect.

echo "<a href=\"inventorid.php?inventorid=".$data2['inventorid']."\">".$data2['inventorid']." ".$data2['firstname']." ".$data2['lastname']."</a>\n";

is the correct syntax.
Also, to make life simple, you can use,

$inventorid = $data2['inventorid'];
$firstname = $data2['firstname'];
$lastname = $data2['lastname'];
echo "<a href='inventorid.php?inventorid=$inventorid'>$inventorid $firstname $lastname</a>\n";

Cheers!

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.