I am reading emails from database. And i want to echo the emails as hyperlink, but its not working.
<?php
$un = $_POST['username'];
$pw = $_POST['password'];
// connect to the db
$user = 'proc';
$pswd = 'passwd';
$db = 'school';
$conn = mysql_connect('localhost', $user, $pswd);
mysql_select_db($db, $conn);
// run the query to search for the username and password the match
$query = "SELECT email AS text FROM contact";
$result = mysql_query($query) or die("Unable to verify user because : " . mysql_error());
// this is where the actual verification happens
while ($row = mysql_fetch_assoc($result)) {
echo ("\n".$row['text']);
echo "<a href=.$row['text']>some text</a>";
}
?>
Any idea what is wrong in my code?
You cannot embed variables in doubly-quoted strings like that in all cases. Here’s what you can do:
or
Personally I prefer the second form because it has historically been easier to see at a glance that a variable is being embedded through your editor’s syntax highlighting (although today editors might also highlight the first form).
Be aware that your current code has other problems: no quotes around HTML attribute values, and not properly escaping values that get embedded in HTML. Fix that as well with something like
The exact correct form depends on the encoding of your data as well; see
htmlspecialcharsfor the details.