Jump to content

Simple Search


seandarcy

Recommended Posts

Hi

 

Im trying to create a simlpe mysql database search.

 

I have a database called "lever" and then a table called "faults"  Inside the table i have the following titles:

Incident

School

Person

Summary

 

I want a search field that uses the "incident" filed to display data only in that row.

I would like it to be displayed on a html page.

 

Is anyone able to help me with the code. Ive tried using some that have been suggested on the web but I cant seem to configure them correctly.

 

Hope someone can help.

Link to comment
https://forums.phpfreaks.com/topic/57564-simple-search/
Share on other sites

ive got this but it doenst work:

 

$db_host = 'localhost';

$db_user = 'MYUSERNAME';

$db_pass = 'MYPASSWORD';

$db_name = 'lever';

$db_table = 'faults';

$conn = mysql_connect($db_host,$db_user,$db_pass);

mysql_select_db($db_name,$conn);

 

// ---- END CONFIGURATIONS ------------------------------------------//

 

if ($incident == "")

{$incident = '%';}

 

$result = mysql_query ("SELECT * FROM $dbase_name

WHERE incident LIKE '%$incident%'

",$conn);

 

$row = mysql_fetch_array($result) or die(mysql_error());

 

do {

PRINT "Our database contains the following records: <br><br>";

PRINT "<b>incident: </b> ";

print $row["incident"];

print (" ");

print ("<br>");

PRINT "<b>summary: </b> ";

print $row["summary"];

print ("<p>");

print ("<p>");

} while($row = mysql_fetch_array($result));

print "</table>"; 

 

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/57564-simple-search/#findComment-285611
Share on other sites

have i changed the right bit as i now get the following error:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/darcynet/public_html/code/results.php on line 19

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE incident LIKE '%%%'' at line 2

 

<?

$db_host = 'localhost';

$db_user = 'username';

$db_pass = 'password';

$db_name = 'lever';

$db_table = 'faults';

$conn = mysql_connect($db_host,$db_user,$db_pass);

mysql_select_db($db_name,$conn);

 

// ---- END CONFIGURATIONS ------------------------------------------//

 

if ($incident == "")

{$incident = '%';}

 

$result = mysql_query ("SELECT * FROM $dbase_name

WHERE incident LIKE '%".$incident."%'

",$conn);

 

$row = mysql_fetch_array($result) or die(mysql_error());

 

do {

PRINT "Our database contains the following records:

 

";

PRINT "incident: ";

print $row["incident"];

print (" ");

print ("

");

PRINT "summary: ";

print $row["summary"];

print ("<p>");

print ("<p>");

} while($row = mysql_fetch_array($result));

print "</table>"; 

 

?>

 

Link to comment
https://forums.phpfreaks.com/topic/57564-simple-search/#findComment-285625
Share on other sites

you are passing an invaliid argument caused by

{$incident = '%';} that is not need as u have hardcoded the % values allready so set it as nothing

{$incident = '';}

again u need something for the query to work

 

looks like ur not passing a value into $incident

 

what is $incident surpose to be a value of?

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/57564-simple-search/#findComment-285670
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.