Page 1 of 1

Need the simplest PHP search with mysqli

Posted: Tue Mar 10, 2015 2:05 pm
by fokeiro
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:


Image

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:
Image
Image



thank you for anyone providing any help.

Re: Need the simplest PHP search with mysqli

Posted: Tue Mar 10, 2015 2:57 pm
by Celauran
You've got a mix of mysql_ and mysqli_ functions in there. Has to be one or the other.

Re: Need the simplest PHP search with mysqli

Posted: Tue Mar 10, 2015 6:17 pm
by fokeiro
Celauran wrote:You've got a mix of mysql_ and mysqli_ functions in there. Has to be one or the other.
fixed it now it works but is there a way to extra the data without using the password ? i want to put it online but dont want the code to have my pass

Re: Need the simplest PHP search with mysqli

Posted: Tue Mar 10, 2015 7:31 pm
by Celauran
Not really. You need a password to connect to the DB, there's no way around that. It's not visible to the outside and if someone has access to the files on your server, it's already game over. Just make sure you keep it outside of version control.