# Searching a database

**URL:** <https://forum.kirupa.com/t/searching-a-database/145650>\
**Category:** Uncategorized\
**Created:** [April 24, 2005, 4:46pm UTC](https://forum.kirupa.com/t/searching-a-database/145650 "2005-04-24T16:46:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dreamerp](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@dreamerp](https://forum.kirupa.com/u/dreamerp)\
**Post date:** [April 24, 2005, 4:46pm UTC](https://forum.kirupa.com/t/searching-a-database/145650/1 "2005-04-24T16:46:21Z")

</div>

Hello,  
I am selecting information from a database based on form results.

```php
<?php

$type = $_POST['type'];
$search = $_POST['search'];

 $dbcnx = mysql_connect("localhost", "username", "password"); 
mysql_select_db("database");
 
$result = mysql_query("SELECT * FROM news WHERE $type='$search'");
 
if ($result == "")
{
print "We could not find a match for the search query $search in the search type: $type";
exit();
} else {
	 while ($row = mysql_fetch_array($result) ) { 
 $msgid = $row["msgid"];
 $author = $row["poster"];
 $message = $row["message"];
 $title = $row["title"];
 
print "$title / $message / $author<br> ";
}}
?>

```

It displays information if it finds it, but it doesn’t show the error if nothing is found. What is wrong with the

```php
if ($result == "")
{
print "We could not find a match for the search query $search in the search type: $type";
exit();
} 

```

?

Thanks!
