mysqli从表返回错误中选择数据

时间:2015-08-19 01:17:07

标签: php mysql mysqli

我是新手,但设法将我的问题跟踪到这个错误:

  

错误描述:'where clause'0

中的未知列'huhuhu'

查询:

$sql = mysqli_query($mysqli, "SELECT description FROM cscart_postcode_location_descriptions WHERE description = ".$postcode_q." LIMIT 1");

似乎正在寻找$postcode_q中的一列,但这正是我想要搜索的内容。这是一个名为“cscart_postcode_location_descriptions”的表,希望在该表中的“description”列中搜索传递给$postcode_q的值。

有什么想法吗?

更新

<?php

//if we got something through $_POST
if (isset($_POST['postcode_locator_search'])) {
    // here you would normally include some database connection
    //include('config.local.php');

    //Open a new connection to the MySQL server
    $mysqli = new mysqli('localhost','test','c@W)ukmd[0bm','test');

    //Output any connection error
    if ($mysqli->connect_error) {
        die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
    }

    // never trust what user wrote! We must ALWAYS sanitize user input
    $postcode_q = mysqli_real_escape_string($mysqli, $_POST['postcode_locator_search']);
    //$postcode_q = htmlentities($postcode_q);

    // A select query. $result will be a `mysqli_result` object if successful
    $sql = mysqli_query($mysqli, "SELECT description FROM cscart_postcode_location_descriptions WHERE description = '".$postcode_q."' LIMIT 1");
    echo("Error description: " . $postcode_q);

    if($result === false or mysqli_error($mysqli) === 0) {
        // Handle failure - log the error, notify administrator, etc.
        echo '1';
    } else {
        echo "0";
    }

    $mysqli->close();

}
?>

0 个答案:

没有答案