Please see here
expression of successful query
if ($conn->query($sql) === TRUE) {
echo "";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
Please see my code:
<form action="" type="text" method="get">
<div>
:
<input type="text" name="keyword">
<select id="" name="sel">
<option value="title"></option>
<option value="content"></option>
<input type="submit" value="">
</select>
</div>
</form>
<?php
require("conn.php");
$keyword = trim($_GET["keyword"]);
$sel = $_GET["sel"];
$sql = "SELECT * FROM lyb where $sel " . " like "%$keyword%"";
if ( $mysqli->query($sql) === TRUE) {
echo "<br />";
} else {
echo "</br />" . $mysqli->error;
}
$result = $mysqli->query($sql);
echo "$result->num_rows"."<br />";
var_dump($result);
?>
query failed
20
object (mysqli_result)-sharp2 (5) {["current_field"] = > int (0) ["field_count"] = > int (8) ["lengths"] = > NULL ["num_rows"] = > int (20) ["type"] = > int (0)}
inconsistency, ha,
1. The query failed, why are there still 20 results?
2. If the query fails, why. $mysqli- > error has no output?