Sign in to follow this  
wild20

How To Make A Search Form And Php Code? Can you help please?

Recommended Posts

Thanks for the codes.........

I tried the php code and it is showing like

[color=#FF0000]Fatal error: Call to a member function query() on a non-object in C:wampwwwstudent_databasephpsearch.php on line 20[/color]
please help me to correct this error.................

Share this post


Link to post
Share on other sites
:)

aight, I made somthing to what I think your asking. If you go to the church site I made: CBF , it has a area where you can search for sermons in a database.I'm thinking your using PHP 5.
aighy, here you go man... just wrote this up real quik for yu, very simple, hope it works for you :blink:
, Arctic

html form:

<html>	<head>		<title>Search Test</title>	</head>	<body topmargin="0" leftmargin="0">		<form action="search.php" method="post">			Search Term <input type="text" name="searchterm"><br />			<input type="submit" value="Search">		</form>	</body></html>

php search.php:

<?php/*set varibles from form */$searchterm = $_POST['searchterm'];trim ($searchterm);/*check if search term was entered*/if (!$searchterm){	echo 'Please enter a search term.';}/*add slashes to search term*/if (!get_magic_quotes_gpc()){$searchterm = addslashes($searchterm);}/* connects to database */@ $dbconn = new mysqli('host', 'username', 'password', 'database'); if (mysqli_connect_errno()) { echo 'Error: Could not connect to database.  Please try again later.'; exit;}/*query the database*/$query = "select * from tablename where tablerow like '%".$searchterm."%'";$result = $dbconn->query($query);/*number of rows found*/$num_results = $result->num_rows;echo '<p>Found: '.$num_results.'</p>';/*loops through results*/for ($i=0; $i <$num_results; $i++){ $num_found = $i + 1; $row = $result->fetch_assoc(); echo "$num_found. ".($row['tablerow'])." <br />";}/*free database*/$result->free();$dbconn->close();?>

oh, and your right, never alone with Christ, he reigns 4-ever
not bad :)

Share this post


Link to post
Share on other sites

hey how can we select only one row from the database dat matches with the entered text ?? plzz help...by writing this code m getting all d rows in the databse..plzz do the needfulll thankxxx..


<?php$host="localhost";$username="poojar";$password="abc";$database="allsites";mysql_connect($host,$username,$password);@mysql_select_db($database) or die( "Unable to select database");$result = mysql_query("SELECT websitename,result FROM searchresult");while($row = mysql_fetch_array($result))  {  echo $row['websitename'] ." " . $row['result'];  echo "<br />";  }mysql_close();

?>

Share this post


Link to post
Share on other sites

hey how can we select only one row from the database dat matches with the entered text ?? plzz help...by writing this code m getting all d rows in the databse..plzz do the needfulll thankxxx..

<?php$host="localhost";$username="poojar";$password="abc";$database="allsites";mysql_connect($host,$username,$password);@mysql_select_db($database) or die( "Unable to select database");$result = mysql_query("SELECT websitename,result FROM searchresult");while($row = mysql_fetch_array($result))  {  echo $row['websitename'] ." " . $row['result'];  echo "<br />";  }mysql_close();

?>

Ah, your issue is that you have it set to "continue looping as long as there's more data." What you want to do is instead of have a while loop just erase the entire loop and output row 0 (which is really the first row).

Share this post


Link to post
Share on other sites

Great work!!In my table I have 4 fields “First_name, Last_name, Phone_number, Affilation.Is there any way to view all fields as search result?Thanks for any help,Cibsrk

Share this post


Link to post
Share on other sites

Hello everyone. I'm a newbie in php. I did an online system for school project, my prof wants to add me a search box and also reports and I have to present it by next week.. Can anyone help me here? Please mail me at mcr_Still21@yahoo.com :(I would really appreciate any kind of help. Thank you so much.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this