PHP - Can Anyone Help Me Create Search Script?
Hello,can anyone help me create members search script?
here is image example
here is 'users 'table
`id` int(11) NOT NULL auto_increment, `age` varchar(200) collate utf8_unicode_ci NOT NULL, `city` varchar(200) collate utf8_unicode_ci NOT NULL, `username` varchar(30) collate utf8_unicode_ci NOT NULL, `password` varchar(150) collate utf8_unicode_ci NOT NULL, `salt` varchar(10) collate utf8_unicode_ci NOT NULL, `mgroup` int(3) NOT NULL, `email` varchar(100) collate utf8_unicode_ci NOT NULL, `ip` varchar(15) collate utf8_unicode_ci NOT NULL, `posts` int(11) NOT NULL, `date_joined` varchar(25) collate utf8_unicode_ci NOT NULL, `logged_in` int(1) NOT NULL default '0', `last_action_time` int(25) NOT NULL, `signature` text collate utf8_unicode_ci NOT NULL, `avatar` varchar(300) collate utf8_unicode_ci NOT NULL default 'default', `what_is_doing` varchar(30) collate utf8_unicode_ci NOT NULL, `what_is_doing_id` varchar(100) collate utf8_unicode_ci NOT NULL, `name` varchar(200) collate utf8_unicode_ci NOT NULL, `website` varchar(200) collate utf8_unicode_ci NOT NULL, `title` varchar(150) collate utf8_unicode_ci NOT NULL, `rank_pips` int(11) NOT NULL, `friends` tinytext collate utf8_unicode_ci NOT NULL, `blocks` tinytext collate utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;Please help me? Edited by sopranolv, 30 January 2015 - 05:26 AM. Similar TutorialsThe result pages is supposed to have pagination like google help me please
Hello. I am working on a php script for searching a database table. I am really new to this, so I used the this tutorial http://www.phpfreaks.com/tutorial/simple-sql-search I managed to get all the things working the way I wanted, except one important and crucial thing. Let me explain. My table consist of three columns, like this: ID(bigint20) title(text) link (varchar255) ============================= ID1 title1 link-1 ID2 title2 link-2 etc... Like I said, I managed to make the script display results for a search query based on the title. Want I want it to do more, but I can't seem to find the right resource to learn how, is to place a "Download" button under each search result with its corresponding link from the table. Here is the code I used. <?php $dbHost = 'localhost'; // localhost will be used in most cases // set these to your mysql database username and password. $dbUser = 'user'; $dbPass = 'pass'; $dbDatabase = 'db'; // the database you put the table into. $con = mysql_connect($dbHost, $dbUser, $dbPass) or trigger_error("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($dbDatabase) or trigger_error("Failed to connect to database {$dbDatabase}. Error: " . mysql_error()); // Set up our error check and result check array $error = array(); $results = array(); // First check if a form was submitted. // Since this is a search we will use $_GET if (isset($_GET['search'])) { $searchTerms = trim($_GET['search']); $searchTerms = strip_tags($searchTerms); // remove any html/javascript. if (strlen($searchTerms) < 3) { $error[] = "Search terms must be longer than 3 characters."; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } // If there are no errors, lets get the search going. if (count($error) < 1) { $searchSQL = "SELECT title, link FROM db WHERE title LIKE '%{$searchTermDB}%'"; $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); if (mysql_num_rows($searchResult) < 1) { $error[] = "The search term provided {$searchTerms} yielded no results."; }else { $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$row['title']}<br /> Download - this is the button I want to link to the title results - and maybe other links too - <br /> "; $i++; } } } } function removeEmpty($var) { return (!empty($var)); } ?> <?php echo (count($error) > 0)?"The following had errors:<br /><span id=\"error\">" . implode("<br />", $error) . "</span><br /><br />":""; ?> <form method="GET" action="search?" name="searchForm"> Search for title: <input type="text" name="search" value="<?php echo isset($searchTerms)?htmlspecialchars($searchTerms):''; ?>" /> <input type="submit" name="submit" value="Search" /> </form> <?php echo (count($results) > 0)?"Rezultate lucrari de licenta sau disertatie pentru {$searchTerms} :<br /><br />" . implode("", $results):""; ?> $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$row['title']}<br /> Download - this is the button I want to link to the title results - and maybe other links too - <br /> "; $i++; I would like the results to be displayed like this Results for SearchItem: Result 1 Download | Other link Result 2 Download | Other link etc.... or something like this. So, how do I add the data from the link row into a text(Dowload), within an <a href> tag (well, at least I guess it would go this way) ? My first tries (fueled by my lack of knowledge) where things like $results[] = "{$row['title']}<br /> <a href="{$row['link']}">Download</a> <br /> "; but I keep getting lots of errors, and then I don't know much about arrays and stuff (except basic notions); So there it is. I am really stuck and can't seem to find any workaround for this. Any suggestions? (examples, documentation, anything would do, really) Thanks, Radu Basically I have a property page where I want users to be able to click 'detached' and then only detached properties will appear, if the user click 'semi-detached' then only semi-detched properties will appear. but these properties that I want to appear are just images, then a link to the actually property page with all the details. You can view the page here to get a better understanding: http://www.mumtazproperties.hostei.com/forsale.html At the moment all of the properties appear on the page. (and when you select the filters it actually does what I want it too, but through HTML) But I want the information to come from a database and then use PHP code to execute it all. Help is hugely appreciated, thanks. I have a property website and I want users to be able to filter the properties, So when they access the page, and click 'detached properties' only detached properties will appear, if the user selects 'semi-detached' then only semi detached properties will appear. I already have a mySQL database set up. Image attached here to have a better understanding. I am currently looking to have two pages, one with a search form (textbox and button) and output the results (from database table) based on the strings input to another page. how do i achieve this? i just want something very simple nothing too complex and advanced please hi i'm trying to create a php file from a script but i dont seem to be getting it right the file doesn't exist already am trying to create it. Code: [Select] <title>test</title> <?php include_once"includes/db_connect.php"; $sql=mysql_query("SELECT `urlName` FROM `products` WHERE `category`='1'"); while($fetch=mysql_fetch_object($sql)){ $File = "".$fetch->urlName.".php"; $handle = fopen($File, 'w'); fclose($handle); } ?> I can't find out whats the problem here, would appreciate some input in how to think building my "if".
The problem is that I don't seem to catch if an email exists, nor if user exists and neither can I create a new user :/.
Appreciate your help alot!
<?php // Start the session in case of errors to display within the page of user creation session_start(); $err_msg = array(); $errflag = false; // Check if the submit button was pressed if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_POST['submit'] === 'Skapa') { // Crypt password $options = ['cost' => 10]; $username = strip_tags($_POST['uname']); $password = strip_tags(password_hash($_POST['pword'], PASSWORD_DEFAULT, $options)); $email = strip_tags($_POST['uname'], '@'); // Check so all the fields are filled if ($_POST['uname'] == '' || $_POST['pword'] == '' || $_POST['pwordcheck'] == '') { $err_msg[] = 'Please enter all fields<br>'; $errflag = true; } // See if passwords and confirm matches if ($_POST['pword'] !== $_POST['pwordcheck']) { $err_msg[] = 'Passwords doesn\'t match!<br>'; $errflag = true; } // Check password length, atleast 8 characters if (strlen($_POST['pword']) < 7) { $err_msg[] = 'Password must be atleast 8 characters long'; $errflag = true; } // Check if email exists include_once('../includes/db.inc.php'); $db = new PDO(DB_INFO, DB_USER, DB_PASS); $sql = "SELECT COUNT(*) AS count FROM movies WHERE email = :emailadress"; $stmt = $db->prepare($sql); $stmt->bindParam(':emailadress', $email); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); if ($row > 0) { $err_msg[] = 'Email already taken!'; $errflag = true; $db = NULL; } // Check if user exists include_once('../includes/db.inc.php'); $db = new PDO(DB_INFO, DB_USER, DB_PASS); $sql = "SELECT uname FROM users WHERE uname = :username"; $stmt = $db->prepare($sql); $stmt->bindParam(':username', $username); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); if ($row > 0) { $err_msg[] = 'User already exists'; $errflag = true; $db = NULL; } if ($errflag = false) { // Everything passed, create the user! include_once('../includes/db.inc.php'); $db = new PDO(DB_INFO, DB_USER, DB_PASS); $sql = "INSERT INTO users (uname, pword, email) VALUES (:username, :password, :emailadress)"; $stmt = $db->prepare($sql); $stmt->bindParam(':username', $username); $stmt->bindParam(':password', $password); $stmt->bindParam(':emailadress'); $stmt->execute(); $_SESSION['uname'] = $username; header('Location: ../template/header.php'); exit; } // If any error, send the user back and display messages if ($errflag == true) { $_SESSION['err_msg'] = $err_msg; session_write_close(); header('Location: ../user/create.php'); exit; } } else { $_SESSION['err_msg'] = $err_msg; session_write_close(); header('Location: ../user/create.php'); exit; } ?> I saw the posting for creating a script for a certificate but am struggling to get it to work, i have tried everything I can think of but getting errors.
As you can see from this test link there is php errors that cannot be resolved.
http://gmdesign.org.uk/xxx
I have also added the javascript to a button to print the certificate it but its not working either.
I would be grateful for any help you can give.
you can download/see my full scripts by viewing the attached files I am looking at the ImageMagick library to create thumbnails from about 800 pdf files. I'd like to use php because the information needs to be stored in a database. Is ImageMagick up to the task? Would you recommend an alternative library? Any other advice is appreciated. Thanks, -Brian Hi guys, Before I am going to create php script to make a proxy detection, I want to ask that if it possible to create a method that checking whether if the proxy server is a located governments or fbi. Is it possible? If so, what method I would use? Thanks, Mark I've decided to "re-learn" PHP. I've created a registration script which works well, however, the login script is not going to plan for me. This is the script: <?php include "./global/global.php"; ?> <?php error_reporting (E_ALL ^ E_NOTICE); ?> <?php $username = $_POST['username']; $password = $_POST['password']; $submit = $_POST['submit']; if($submit){ $sql1 = "SELECT * FROM test2 WHERE username = '".$username."'"; $res1 = mysql_query($sql1) or die(mysql_error()); $numrows = mysql_num_rows($res1); if($numrows != 0){ while($row = mysql_fetch_assoc($res1)){ $dbusername = $row['username']; $dbpassword = $row['password']; } if($username==$dbusername && $password==$dbpassword){ ob_start(); $_SESSION['username']=$username; header("Location: index.php"); } }else{ echo("That user doesn't exist!"); } }else{ ?> <form action="login.php" method="POST"> <input type="text" name="username" /> <input type="password" name="password" /> <input type="submit" name="submit" value="Login" /> </form> <?php } ?> The problem is that it isn't building the session, so when I go back to the homepage, which looks like this: <?php include "./global/global.php"; session_start(); ?> <?php error_reporting (E_ALL ^ E_NOTICE); ?> <html> <?php if($_SESSION){ echo("Welcome, ".$_SESSION['username']); }else{ echo("Please login <a href='login.php'>here</a>"); } ?> </html> It shows that I should login. I can't seem to see what's wrong because I have a script very similar to it and it works fine, so if anyone could help, I'd appreciate it. Honestly, for something like this I don't know how to go about creating this script.. So I want to create a script that will generate every combination of 2 numbers that range from 0-749, so 750x750 = 562500 possible combinations, so for example, 0/749, 43/87, 0/0, 1/1, 2/1, 1/2, 500/450, 405/673, etc.. How would I go about starting to write a script that can generate all of the possible combinations and and put them in an array or write them to a file? Thanks for the help in advanced! -CLUEL3SS hello i need a script that sends data from the searchbar to a search.php and there the entries are displayed with the category someone knows how to write it or has someone an example https://prnt.sc/ujzvuf When I open the page in browser it list everything that's in my DB without searching for anything. What is wrong to make it do this? Code: [Select] <form method="post" action="<?=$PHP_SELF?>"> <center> <table border="0" cellpadding="0" width="100%"> <tr> <td width="30%"> <p align="right">Search For GID Number:</p></td> <td width="80%"><input type="text" name="searchterm"></td> </tr> </table> </center> <p align="left"> <input type="submit" value="Search"><br><br> </form> <?php include('fbvar.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($databaseserver, $databaseuser, $databasepass, $databasename); if (mysqli_connect_errno()) { echo 'Error: Could not connect to database. Please try again later.'; exit; } /*query the database*/ $query = "SELECT gid, gift FROM $gifts WHERE gift like '%".$searchterm."%' ORDER BY gid"; $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['gid']).' '.($row['gift'])." <br />"; } /*free database*/ $dbconn->close(); //End of the Search Database form ?> I would like to edit this script's SQL query to SELECT FROM multiple tables within my database. Can this be done first of all and what would i need to change? here's the script: Code: [Select] <?php // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=10; // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } //connect to your database ** EDIT REQUIRED HERE ** mysql_connect("host","username","password"); //(host, username, password) //specify database ** EDIT REQUIRED HERE ** mysql_select_db("database name") or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "select * from the_table where 1st_field like \"%$trimmed%\" order by 1st_field"; // EDIT HERE and specify your table and field names for the SQL query $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); // If we have no results, offer a google search as an alternative if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; echo "<p><a href=\"http://www.google.com/search?q=" . $trimmed . "\" target=\"_blank\" title=\"Look up " . $trimmed . " on Google\">Click here</a> to try the search on google</p>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: "" . $var . ""</p>"; // begin to show results set echo "Results"; $count = 1 + $s ; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["1st_field"]; echo "$count.) $title" ; $count++ ; } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> All i want it to do is search a field in 3 different tables in my database called "postcode" and return search results. Ive seen the JOIN feature but don't know how to use it, any help i would appreciate. Thank you. I am building a simple search engine script for my website which allows users to search for electronic devices that we have in our database. Here is the HTML code. Code: [Select] <form name="search" action="search.php" method="get"> <input type="text" name="query" size="50" /> <input type="submit" name="submit" value="Search" /> </form> Here is the PHP code. <?php error_reporting(0); include 'config.php'; mysql_connect("localhost", "root", "password") or die(mysql_error()); mysql_select_db("maindatabase") or die(mysql_error()); // get the data from the form $search_query = $_GET['query']; // mysql query $query = mysql_query("SELECT * FROM `products` WHERE productName LIKE '%$search_query%'"); $count_rows = mysql_num_rows($query); echo "Results found: " . $count_rows; ?> Here is the problem: Whenever I enter a single keyword in the search, the search brings some results. BUT, whenever I enter multiple keywords, the search brings 0 rows. For example: I have a product called Sony Bravia Television 42 inches - 1080p HD in my database. When type "sony" in the search and press the search button, I only get 1 row as the result. But when I enter "sony television" in the seach, I get 0 row results. Why is that? What can I do to fix this problem? I want to return results that contain all the keywords that the search query had. Just like any search engine: Google, Yahoo, etc. hi guys, i'm working for some time now on a project and i'm really struggeling with 1 part of the project. What is the input for the script? the input for the script are numbers(1234) or number - letter combinations (xtx-12-34). also important to know is that $_POST['ordernummer']; can hold multiple inputs divided by a "," (like 1234,9876,1597) Database setup. my sql database has data stored, these numbers or number - letter combinations are in 1 collum. there are (ofc) more collums. What do i need. I need the input to be ordered by customer_name. below i have pasted the script the i have atm. It only works with numbers, as soon as i start to add letters, it dies. After some asking around it turns out the query is wrong, but i have no clue how i'm gone get the data i need. hopefully, after reading the code, you'll understand i bit better what i need $Ordernummer = $_POST['ordernummer']; $allorders[0] = ""; $query1 = mysql_query("SELECT CUSTOMER_NAME,COMP_ULL_ORDER_NUM_DOSSIER_NUM,ORDER_EINDGEBRUIKER,CUSTOMER_SEGMENT FROM data WHERE COMP_ULL_ORDER_NUM_DOSSIER_NUM IN (".$Ordernummer.") GROUP BY CUSTOMER_NAME "); while(list($customer,$ordernr)= mysql_fetch_row($query1)){ $query2 = mysql_query("SELECT CUSTOMER_NAME,COMP_ULL_ORDER_NUM_DOSSIER_NUM,ADDRESS_INST_STREET,ADDRESS_INST_NUMBER,ADDRESS_INST_ZIPCODE,ADDRESS_INST_CITY,CUSTOMER_SEGMENT,ORDER_EINDGEBRUIKER FROM data WHERE CUSTOMER_NAME='$customer' AND COMP_ULL_ORDER_NUM_DOSSIER_NUM IN (".$Ordernummer.") ORDER BY CUSTOMER_NAME "); while(list($cust,$order,$street,$housenr,$zip,$city)=mysql_fetch_row($query2)){ $full_line = $order." - ".$street." ".$housenr.", ".$zip.", ".$city."<br>"; $allorders[0] .= $full_line; } echo "<br>Customer: ".$customer." <br> Location(s) impacted:<br> ".$allorders[0]. "<br>"; $allorders[0] = ""; } so, like i said, i know atm no safety is added (sql injection). and query1 is wrong (i'm told, but i get the results i need) hope you some can help me, any help is greatly appreciated thanks! nathan ps, sorry for the bas English, i'm not a native English speaker/writer I wrote this script to query the database and get the count between timestamps. I'm using strtotime to convert the user selected date and the pre-selected times into a usable timestamp to search with. I've echo the first one to ensure that it's creating the correct timestamp with time and it is. The problem is that it's returning data that's outside of the time. I don't know if it's my php or mysql, so I was hoping one of you could help. Thanks! Code: [Select] <?php /** * @author William Morris * @copyright 2010 */ include('inc/db.php'); $startdate = "2010-07-01"; $enddate = "2010-08-05"; echo "Start Date: ".$startdate."<br>"; echo "End Date: ".$enddate."<br>"; //convert dates into timestamp $startdate1 = strtotime($startdate."00:00:00"); $enddate1 = strtotime($enddate."11:59:59"); echo "Start Date 1: ".$startdate1."<br>"; echo "End Date 1: ".$enddate1."<br>"; //convert dates into morning timestamp $startdate1 = strtotime($startdate."06:00:00"); $enddate1 = strtotime($enddate."11:59:59"); $sql = mysqli_query($conn, "SELECT COUNT(event_time) FROM `event` WHERE event = 'Registration' AND event_time BETWEEN '$startdate1' AND '$enddate1'"); $row = mysqli_fetch_array($sql); //convert dates into afternoon timestamp $startdate2 = strtotime($startdate."12:00:00"); $enddate2 = strtotime($enddate."17:59:59"); $sql1 = mysqli_query($conn, "SELECT COUNT(event_time) FROM `event` WHERE event = 'Registration' AND event_time BETWEEN '$startdate2' AND '$enddate2'"); $row1 = mysqli_fetch_array($sql1); //convert dates into Evening timestamp $startdate3 = strtotime($startdate."18:00:00"); $enddate3 = strtotime($enddate."23:59:59"); $sql2 = mysqli_query($conn, "SELECT COUNT(event_time) FROM `event` WHERE event = 'Registration' AND event_time BETWEEN '$startdate3' AND '$enddate3'"); $row2 = mysqli_fetch_array($sql2); //convert dates into night timestamp $startdate4 = strtotime($startdate."00:00:00"); $enddate4 = strtotime($enddate."05:59:59"); $sql3 = mysqli_query($conn, "SELECT COUNT(event_time) FROM `event` WHERE event = 'Registration' AND event_time BETWEEN '$startdate4' AND '$enddate4'"); $row3 = mysqli_fetch_array($sql3); echo "<table width='50%' border='0'> <tr> <td bgcolor='#d3d3d3'><div align='center'>Morning (6am-12pm)</div></td> <td bgcolor='#d3d3d3'><div align='center'>Afternoon (12pm-6pm)</div></td> <td bgcolor='#d3d3d3'><div align='center'>Evening (6pm-12am)</div></td> <td bgcolor='#d3d3d3'><div align='center'>Night (12am-6am)</div></td> </tr>"; echo "<tr> <td><div align='center'>".$row['COUNT(event_time)']."</div></td> <td><div align='center'>".$row1['COUNT(event_time)']."</div></td> <td><div align='center'>".$row2['COUNT(event_time)']."</div></td> <td><div align='center'>".$row3['COUNT(event_time)']."</div></td> </tr>"; echo "</table>"; ?> I'm getting a blank screen when I run the following search script. The script should retrieve news entries from the db which contain the keyword and echo those entries with the keyword highlighted in yellow. Could anyone shed light on why the script isn't running as it should?... Thanks in advance if you can help. Code: [Select] <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { // form submitted if(!empty($_POST['keywords'])) { // search term has been entered $keywords = trim($_POST['keywords']); $search_exploded = explode(" ", $keywords); include('includes/mysqli_connect.php'); // connect to db // execute query $q = "SELECT title, subtitle, news_entry FROM news WHERE title LIKE '%$keywords%' OR subtitle LIKE '%$keywords%' OR news_entry LIKE '%$keywords%' "; $r = mysqli_query($dbc, $q); // If results were found, output them $retrieved = mysqli_num_rows($r); if (@mysqli_num_rows($r) > 0) { echo "<h3>" . $retrieved . ' result(s) found, as follows:</h3>'; while ($row = mysqli_fetch_array($r)) { echo "<div class='news_borders_top_bottom'>" . '<h1>' . $row['title'] = str_replace($_POST['keywords'], "<div class='highlight'>{$_POST['keywords']}</div>", $row['title']); . '</h1>' . '<h2>' . $row['subtitle'] = str_replace($_POST['keywords'], "<div class='highlight'>{$_POST['keywords']}</div>", $row['subtitle']); . '</h2>' . '<p>' . $row['news_entry'] = str_replace($_POST['keywords'], "<div class='highlight'>{$_POST['keywords']}</div>", $row['news_entry']); . '</p>' . '<div class="created_on">Created on: ' . $row['created'] . '</div></div>'; } mysqli_close($dbc); echo "<p><a href='search_archive.php'>Search again</a></p>"; ?> </div> </div> <?php include('includes/footer.php'); exit(); } else { // no matches echo "No news entries were found which matched your search criteria."; } } else { // no search term entered echo "Please enter a search term."; } } else { // search button not yet clicked so show form ?> <h1>Search News Archive</h1> <form method="post" action="search_archive.php" id="searchform"> <p><input type="text" id="keywords" name="keywords"> </p> <p><input type="submit" name="submit" value="Search!"> </p> </form> </div> </div> <?php } ?> Hello PHPFreaks, I am busy with creating a search script that will search the database. I got it working so far but i want it to search for not only one thing but several things so actually make options in the form that you you choose only to search on name or only on address. How do i do this? The PHP code: Code: [Select] <?php mysql_connect ("localhost", "username","password") or die (mysql_error()); mysql_select_db ("database table"); $term = $_POST['term']; $sql = mysql_query("select * from databasetable where naam like '%$term%'"); while ($row = mysql_fetch_array($sql)){ echo "<center>"; echo "<table width='600px'>"; echo "<tr>"; echo "<td><b>Naam:</b> </td><td>".$row['naam']; echo "</td><td><b>Telefoon:</b> </td><td>".$row['telefoon']; echo "</td></tr><tr>"; echo "<tr>"; echo "<td><b>Adres:</b> </td><td>".$row['adres']; echo "</td><td><b>Mobiel:</b> </td><td>".$row['mobiel']; echo "</td></tr><tr>"; echo "<tr>"; echo "<td><b>Postcode:</b> </td><td>".$row['postcode']; echo "</td><td><b>E-mail:</b> </td><td>".$row['email']; echo "</td></tr><tr>"; echo "<tr>"; echo "<td><b>Woonplaats:</b> </td><td>".$row['woonplaats']; echo "</td></tr>"; echo "</table>"; echo "<br /><br />"; echo "<table width='400px'>"; echo "<tr>"; echo "<td><b>Datum:</b> </td><td>".$row['datum']; echo "</td></tr><tr><td><b>Probleem:</b> </td><td>".$row['probleem']; echo "</td></tr><tr>"; echo "<td><b>Mogelijke oplossing:</b> </td><td>".$row['oplossing1']; echo "</td></tr><tr><td><b>Oplossing:</b> </td><td>".$row['oplossing2']; echo "</td></tr><tr>"; echo "<td><b>Wachtwoord:</b> </td><td>".$row['wachtwoord']; echo "</td><tr><td><b>Geschatte Prijs:</b> </td><td>".$row['prijs']; echo "</td></tr><tr>"; echo "<td><b>Bijgeleverd:</b> </td><td>".$row['bijgeleverd']; echo "</td></tr>"; echo "</table><br />"; echo "---------------------------------------------------------------------------------------"; echo "</center>"; echo "<br/><br/>"; } ?> HTML Form: Code: [Select] <form action="search.php" method="post"> <b>RMA Zoeken:</b><br /> <input type="text" name="term" /><br /><br /> <input type="submit" class="art-button" name="submit" value="Submit" /> </form> |