Ok, I've gotten farther but now have another problem. When I execute this code below I get this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\clinicalhome.php on line 77
No results where found sorry
I know this is an ambigious error and could mean a lot of things according to what I found on line. Anyone have any suggestions?
<?php
// Search Code
// Standard Connection Data.
$db_host = "localhost";
//$db_user = "myusername";
//$db_pass = "password";
//mysql_connect("localhost");
//mysql_select_db("cpdata" user="root" password=" ");
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Not connected : ' . mysql_error());
}
// make cpdata the current db
$db_selected = mysql_select_db('cpdata', $link);
if (!$db_selected) {
die ('Can\'t use cpdata : ' . mysql_error());
}
//$db_name = "cpt_info";
//$dbac = mysql_connect($db_host);
//mysql_select_db ($db_name) or die ("Cannot connect to database");
if (!$_POST['search']){
// Breaking out of php to display the form.
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "****://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta ****-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CPT Search Form</title>
<body>
<center><table width="500"><tr><td><p><font size="+1"><center>Clinical Database Search Form<center></font></b></p><br><br><p></p>
<p>This search will result in 4 fields being displayed.</p>
On this form type in what you want to search for, Description, Default CPT.
</td></tr></table><br>
<center><form name="Search Tutorial" method="post" action="">
Enter Your Search Criteria Here:<br>
<label>
<input name="swords" type="text" size="30" maxlength="30">
</label>
<br>
<label>
<input name="search" type="submit" id="search" value="Search">
</label>
</form> </center>
<?php
}else{
// Adding slashes and changing tags so that people trying to take advantage of the system can't
$searchwords = addslashes(htmlspecialchars($_POST['swords']));
// Checking the length of string to make sure its more than 1 characters long
if (strlen($searchwords) < 1){
echo "The selection you have entered is too short, please enter another one.";
}else{
$words = explode(' ',$searchwords);
$totalwords = count($words);
$i = 0;
$searchstring = "";
// Looping to get the search string.
while ($i != $totalwords){
if ($i != 0 and $i != $wordcount){
$searchstring .= " and ";
}
$searchstring .= "description LIKE '%$words[$i]%' or default_cpt LIKE '%$words[$i]%' ";
// Incrementing the value
$i = $i + 1;
}
// Execute the query with the search string just created.
$query = mysql_query("SELECT * FROM cpt_info where $searchstring");
// Check for results
if (mysql_num_rows($query) == 0){
echo "No results where found sorry ";
}else{
while ($fet = mysql_fetch_array($query)){
echo "<p>Description: {$fet['description']}<br />
Default CPT: {$fet['default_cpt']}<br />
Industrial: {$fet['industrial']}<br> />
Federal: {fet['federal']}}</p>";
}// End While
}// End Else
}// End Else
}// End Else
?>
</body></html>