Click here to Skip to main content
14,691,047 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to make a search function in PHP and it from list that have been inner join with status approve. I can do the inner join but im not sure to do a search function from its.

What I have tried:

<!---this is my search form--->

 <div class="form-group">
                    <input class="form-control" id="keywords" name="keywords" type="text" placeholder=" " required data-validation-required-message="Please enter keywords">
                    <p class="help-block text-danger"></p>

 <div class="col-md-2">
                  <div class="form-group">
                    <button id="" class="btn btn-success btn-md text-uppercase" name="search" value="search" type="submit">Search</button>
				 <div class="col-xl-6 col-lg-7 col-md-12">
                <div class="body">
				<?php include 'studSearch.php'?>
					include ('connection.php');
						$= "SELECT * FROM # INNER JOIN owner ON house.ownerNo=owner.ownerNo WHERE status ='APPROVE'";
						$result = mysqli_query($conn,$);
						if (x == TRUE) {
							$no = 1;
							while($row = mysqli_fetch_array(x)){

<!---search function that i try--->

		require 'connection.php';		
		$row = mysqli_query($conn, "SELECT * FROM `#` WHERE `property_type` LIKE '%$keywords%' ") or die(mysqli_error());
		while($result = mysqli_fetch_array($row)){
Updated 26-Jun-20 6:31am

1 solution

Not the problem you've noticed, but something much, much more important: Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.

When you concatenate strings, you cause problems because SQL receives commands like:
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'
The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'
Which SQL sees as three separate commands:
SELECT * FROM MyTable WHERE StreetAddress = 'x';
A perfectly valid SELECT
A perfectly valid "delete the table" command
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.

So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
Member 14871013 26-Jun-20 11:26am
Hey do you know how to delete this question?
OriginalGriff 26-Jun-20 12:02pm
You can't delete a question once you have a reply.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900