Link
Link

Reputation: 403

PHP output to HTML from database

I cant output the values of the row value to the html content any suggestions on how to do that? i tried using different methods so that i will print on the page but it's always blank is there any way to do it?

<?php 

//connect
$dbh=mysql_connect ("localhost", "xxxx_admin", "xxxx") 
   or die ('I cannot connect to the database.');
 mysql_select_db ("xxxx_Client"); 

$term = $_POST['term'];
echo $term;

$sql = mysql_query("select * from ClientTable where FName like '$term'");

if ($row['FName'] == $term){

$ID = $row['ID'];
$FName = $row['FName'];
$LName = $row['LName'];
$PHON = $row['PHON'];

}

else
echo "invalid input";

?>

<html>
<head>
<title></title>
</head>
<body>
asdadasdad<br>

<?php echo $FName; ?><br>a<br>
<?php echo $_POST["$LName"]; ?><br>a<br>

$FName <br>
$LName <br>
$ID <br>
$PHON <br>

sadasdasda
</bod>
</html>

Upvotes: 0

Views: 410

Answers (2)

Paul S.
Paul S.

Reputation: 1573

Try adding error_reporting(E_ALL); near the beginning of your code. There is a good chance that a notice message will tell you what you're doing wrong.

Upvotes: 0

Mike Brant
Mike Brant

Reputation: 71384

First, you are probably not getting any results from your query. Typically when using LIKE you use some form of wildcard in the query like this:

select * from ClientTable where FName like '%$term%'

Second, you are not actually working with the result set.

You need to use some sort of mysql_fetch_array or similar to get the values into $row.

And of course, you really should not be using the mysql_* functions anyway as they are being deprecated in favor of mysqli_* or PDO.

Finally, your need to learn how to prevent SQL injection. Your code is vulnerable now.

Upvotes: 1

Related Questions