deepshah2004 Posted January 23, 2009 Share Posted January 23, 2009 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) Quote Link to comment Share on other sites More sharing options...
Zhadus Posted January 23, 2009 Share Posted January 23, 2009 No password is defined. That gives an undefined variable, access denied, and connection to database failed. Quote Link to comment Share on other sites More sharing options...
printf Posted January 23, 2009 Share Posted January 23, 2009 change this... $query = mysql_query("SELECT * FROM patient WHERE upper($field) LIKE'%$find%' "); to this... $query = "SELECT * FROM patient WHERE upper(" . $field . ") LIKE '%" . $find . "%';"; Also, where is $field coming from? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.