Rares Coco Rares Coco - 1 year ago 59
MySQL Question

search MySQL database using php doesn't work

i need to get something from databse and something don't work, no error and when i write in search bar : alex/bobo/stano nothing happens no message, nothing, only the form with search bar and submit

where is the problem?i can't find it

nume | prenume | id
stano bobo 1
alex bobo 2

Here is the code:

// conectare la baza de date
$db = mysqli_connect("localhost", "root", "", "inregistrare");
$output = '';
$cauta1 = $_POST['cauta'];
$cauta1 = preg_replace("#[^0-9a-z]#i","",$cauta1);

$query = mysqli_query($db, "SELECT * FROM users WHERE nume LIKE '%$cauta1%' OR prenume LIKE '%$cauta1%'");
$count = mysqli_num_rows($db, $query);
if($count == 0){
$output = 'Nu a fost gasit elevul';
while($row = mysqli_fetch_array($query)){
$nume = $row['nume'];
$prenume = $row['prenume'];
$id = $row['id'];

$output .= '<div>'.$nume.' '.$prenume.'</div>';





<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Cauta Elev</title>

<form method="post">
<input type="text" name="cauta" placeholder="Cauta Elevul">
<input type="submit" value="Cauta">

<?php print("$output");

Answer Source

You missed $ for nume and prenume vars in the $output. The correct one is:

$output .= '<div>'.$nume.' '.$prenume.'</div>';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download