Jump to content

Not pulling data


pheidole

Recommended Posts

Getting 0 results

$server = "localhost";
$user = "root";
$pass = "";
$dbname = "st";


$link = mysqli_connect($server, $user, $pass, $dbname);

if (!$link) {
    die();}  
////////////////////////////////////////////////////////////////////////////////////////

 

        if(isset($_REQUEST["term"])){
    $sql = "SELECT * FROM loc WHERE state LIKE '%$name%' ";
    
    if($stmt = mysqli_prepare($link, $sql)){
    
        mysqli_stmt_bind_param($stmt, "s", $param_term);
        
    
        $param_term = $_REQUEST["term"] . '%';
        
       
        if(mysqli_stmt_execute($stmt)){
            $result = mysqli_stmt_get_result($stmt);
            
       
            if(mysqli_num_rows($result) > 0){
            
                while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
                    echo "<p>" . $row["name"] . "</p>";
                }
            } else{
                echo "<p>0</p>";
            }
        } else{
            echo "ERROR:  $sql. " . mysqli_error($link);
        }
    }
     

    mysqli_stmt_close($stmt);
}
 

mysqli_close($link);

database.jpg

Link to comment
Share on other sites

A couple of other points

  • Do not use select *. Specify the columns you need.
  • You are trying to echo $row['name']. The column names in the results of that query are "id" and "state" (a mistake that might have been avoided had you not used "*" in the select)
  • Don't use $_REQUEST. Use $_POST or $_GET - whichever is applicable.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.