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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.