Jump to content

search code does not work as expected


deepshah2004

Recommended Posts

hello I have a search code which should be able to search in any field choosen but it does not work please help

 

code:

 

<HTML>

<HEAD>

<TITLE> search data in the database

</TITLE>

</head>

<BODY bgcolor="white">

 

<?

$host  = 'localhost';

$username = 'root';

$password = '';

$database = 'hospital';

 

// Otherwise we connect to our Database

$connect = mysql_connect($host, $username, $password)

or die("Error connecting: " . mysql_error());

$select = mysql_select_db($database, $connect)

or die("Error selecting DB: " . mysql_error());

 

// We preform a bit of filtering

$find = strtoupper($find);

$find = strip_tags($find);

$find = trim ($find);

 

//Now we search for our search term, in the field the user specified

$query = mysql_query("SELECT * FROM patient WHERE upper($field) LIKE'%$find%' ");

 

?>

 

<font color="black" size="4">

<center>Patient Form Search results

<br>

<br>

<br>

<br>

<table border='1' cellspacing='0' cellpadding='2' bordercolor="black", bgcolor="yellow">

<tr>

<th>id</th>

<th>patientname</th>

<th>diagnosis</th>

<th>fee</th>

<th>doctorsname</th>

</tr>

<?php

 

$run = mysql_query($query)

or die("Error running query: " . mysql_error());

while($row = mysql_fetch_array($run)) {

 

print("\n<tr><td>{$row['id']}</td>");

print("\n<td>{$row['patientname']}</td>");

print("\n<td>{$row['diagnosis']}</td>");

print("\n<td>{$row['fee']}</td>");

print("\n<td>{$row['doctorsname']}</td></tr>"); }

 

$anymatches=mysql_num_rows($run);

if ($anymatches == 0)

{

 

echo "Sorry, but we can not find an entry to match your query<br><br>";

 

}

 

 

 

?>

<br>

<br>

</font>

</table>

</center>

</BODY>

</HTML>

 

Gives me the following errors:

 

Notice: Undefined variable: query in C:\wamp\www\pots & pans ltd2\search query\searchhos3.php on line 46

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\wamp\www\pots & pans ltd2\search query\searchhos3.php on line 46

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\wamp\www\pots & pans ltd2\search query\searchhos3.php on line 46

Error running query: Access denied for user 'ODBC'@'localhost' (using password: NO)

 

Link to comment
https://forums.phpfreaks.com/topic/142104-search-code-does-not-work-as-expected/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.