PHP help

I need to fix this code. It does work if I insert the correct information in the database also when i enter wrong information it gives me an empty page. WHAT I want is to show me a message if I enter wrong data. such as “Result not found”. I try to use IF and Else but I could not get it right

<?php include("config.php"); // connect to database include("heder.php"); ?> <?php $result = mysql_query("SELECT * FROM contacts where phoneNumber LIKE '$_POST[phoneNumber]%' " ) or die (mysql_error()); ?>
<h2>Search result</h2>
<table border="1" cellpadding="5" cellspace="5">



<tr>
<td><?php echo "First Name" ; ?></td>
<td><?php echo "Last Name" ; ?></td>
<td><?php echo "Phone Number" ; ?></td>
<td><?php echo "Zip Code" ; ?></td>
<tr>
<?php while ($row = mysql_fetch_array($result)) { ?>
<tr>
<td><?php echo $row['firstName']; ?></td>
<td><?php echo $row['lastName'];?></td>
<td><?php echo $row['phoneNumber']; ?></td>
<td><?php echo $row['zipCode']; ?></td>
</tr>
<?php } ?>

First off, why are you doing this
[php]


<?php echo "First Name" ; ?>
<?php echo "Last Name" ; ?>
<?php echo "Phone Number" ; ?>
<?php echo "Zip Code" ; ?> [/php]

Just do

[code]


First Name
Last Name
Phone Number
Zip Code [/code]

There are multiple ways to do this

[php]<?php
if(count($result) > 0){
while ($row = mysql_fetch_array($result)) {

		echo'
		<tr>
			<td>'.$row['firstName'].'</td>
			<td>'.$row['lastName'].'</td>
			<td>'.$row['phoneNumber'].'</td>
			<td>'.$row['zipCode'].'</td>
		</tr>';
	}
}else{

	echo'
	<tr>
		<td colspan="4">No results found</td>
	</tr>';
}

?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service