1

This table is created from a database query which is created by a search on another page. I'm trying to make the emails create a link. I'm stumped...

connect script

<?php
    mysql_connect ("localhost","monkey","monkey") or die ("could not connect");
    mysql_select_db("dbtest") or die ("could not find db");
    $output = '';
    // Collect
    if (isset($_POST['search'])) {
        $searchq = $_POST['search'];
        // Query table creation
        $query = mysql_query("SELECT * FROM accounts WHERE LNAME LIKE '%$searchq%'") or die("Could not search.");
        $count = mysql_num_rows($query);

        if($count == 0) {
            $output = 'No results found.';
        } else {
            echo"<table border ='1'>";
            echo"<tr><td>First Name</td><td>Last Name</td><td>Email</td><td>Phone</td></tr>";
            while($row = mysql_fetch_array($query)) {
                echo"<tr><td>{$row['FNAME']}</td><td>{$row['LNAME']}</td><td>{$row['EMAIL']}</td><td>{$row['PHONE_NUMBER']}</td></tr>";
            }
        }
        echo"</table>";
    }
?>
Siegmeyer
  • 4,312
  • 6
  • 26
  • 43
gijoe
  • 11
  • 2
  • 1
    ***Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).*** [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jul 28 '17 at 19:04
  • 1
    [Little Bobby](http://bobby-tables.com/) says ***[your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)***. Even [escaping the string](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) is not safe! – Jay Blanchard Jul 28 '17 at 19:04
  • If an answer solved your problem, consider accepting the answer. Here's how http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work then return here and do the same with the tick/checkmark till it turns green. This informs the community, a solution was found. Otherwise, others may think the question is still open and may want to post (more) answers. You'll earn points and others will be encouraged to help you. *Welcome to Stack!* – Jay Blanchard Jul 28 '17 at 19:46

1 Answers1

0

You just have to put the link in the output:

echo "<tr>
        <td>{$row['FNAME']}</td>
        <td>{$row['LNAME']}</td>
        <td><a href=\"mailto:{$row['EMAIL']}\">{$row['EMAIL']}</a></td>
        <td>{$row['PHONE_NUMBER']}</td>
      </tr>"
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119