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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.