我是新手,但设法将我的问题跟踪到这个错误:
错误描述:'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();
}
?>