PHP/MYSQL query failing but no error -
my mysqli query failing error blank. can tell me problem is, or how can output info on error?
heres php code:
// create connection $conn = new mysqli($hostname, $username, $password, $dbname); // check connection if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } if(isset($_post['in_wordarray'])) { $words = $_post['in_wordarray']; $sql = "select *, ("; $i = 0; foreach ($words $value) { if($i == 0) { $sql .= "(`words` '%$value%')"; } else { $sql .= " + (`words` '%$value%')"; } $i++; } $sql .= ") `nummatches` `mytable` having `nummatches` >= 3 order `nummatches` desc"; //echo $sql; $result = $conn->query($sql); if ($result === true) { $text_result_array = array(); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $text_result_array[] = $row; } // encode response echo json_encode($text_result_array); } } else { echo $conn->error; } } else { echo "bad input"; }
and resulting sql query looks this:
select *, ((`words` '%word1%') + (`words` '%word2%') + (`words` '%word3%')) `nummatches` `words`having `nummatches` >= 3 order `nummatches` desc
sorry i'm not experienced php alone, sure returns boolean?
$result = $conn->query($sql);
if not can remove if statement?
i wrote answer because sadly can't comment yet.
Comments
Post a Comment