0

由于位置不同,公司数据库有重复的 ID 条目,所以我试图通过 ID # AND zip 匹配返回网站上的数据库查询。我可以获得查询数据库的代码并且不返回错误,但它不会从它找到的行中返回结果中的值(只有空白条目)。

有任何想法吗?

$mysqli = new mysqli($host, $user, $password, $dbname);
    if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}        
$searchTerm = $_GET['term']; // GET the search term submitted by the form
$zip = $_GET['term1'];
            $customerNumber = '';
            $progID = '';
            $balance = '';



            $sql = "Select cust_no, zip From teecust where cust_no=? and zip=?";

            // Create the prepared statement
            if($stmt = $mysqli->prepare($sql)){
                $stmt->bind_param("ss", $searchTerm, $zip); // bind the search term to the query where the '?' once was
                if(!$stmt->execute()){ // run the query
    echo $mysqli->error;
    }; 
                $stmt->bind_result($customerNumber, $progID, $balance); // retrieve results into variables
                while($stmt->fetch()){ // loop through results
                    // You now have the result in $customerNumber, $progID, and $balance - do what    you want with it
echo "Customer number: " . $customerNumber . "<br>Date last updated on: " . $progID . "<br> Balance: <strong>$" . $balance . "</strong> ";
                }
                $stmt->close();
            }
        else{
        echo $mysqli->error;
        }

            ?>
4

0 回答 0