Need the simplest PHP search with mysqli
Posted: Tue Mar 10, 2015 2:05 pm
hello, i wonder of anyone here can help me, im trying to create a simple php search , just the bar and a button and populate a table with the info i need. I create this table:

and you can see is been hosted on 1and1.com , and i added a user.
now now on dreamweaver im create this simple php, and it show fine but when i try to look for the name "sigfredo" it doesnt find it
this is my code


thank you for anyone providing any help.

and you can see is been hosted on 1and1.com , and i added a user.
now now on dreamweaver im create this simple php, and it show fine but when i try to look for the name "sigfredo" it doesnt find it
this is my code
Code: Select all
<?php
$host_name = "db568599787.db.1and1.com";
$database = "db568599787";
$user_name = "dbo568599787";
$password = "removed password";
$connect = mysqli_connect($host_name, $user_name, $password, $database);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//collect
if(isset($_POST['search']))
{
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
$query - mysql_query("SELECT * FROM register WHERE name LIKE '%$searchq%' OR profile LIKE '%$searchq%'") or die("cant find user in database");
$count = mysql_num_rows($query);
if($count == 0){
$output = 'There was no search results !!';
}
else
{
while($row = mysql_fetch_array($query)){
$fname = $row['name'];
$lname = $row['profile'];
$uname = $row['information'];
$output .= '<div>'.$fname.' '.$lname.' '.$uname.'</div>';
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JTAG/RGH/PS3 Database</title>
</head>
<body>
<form action="index.php" method="post">
<input type="text" name="search" placeholder="search the database..." />
<input type='submit' value="Search" />
<?php print("$output");?>
</body>
</html>
my questions are what am i doing wrong? and is there a way to not have to use my pass for the database ?
this is what i get:

thank you for anyone providing any help.