插入并获取Undeclared变量:

时间:2017-05-05 14:40:57

标签: php mysql

我执行此multi_query并收到错误:

$date = date('Y-m-d H:i:s');

$searchLimit = $_POST['limitSearch'];        

$inputDate = $_POST['dateSearch'];

$searchDate = date("Y-m-d H:i:s", strtotime($inputDate));

$topic = $_POST['topicSearch'];

foreach($_POST['check_list_search'] as $selected){   

$journal = $selected;

$sql = "SELECT tbl.* FROM (SELECT date, section, title, teaser, href, image FROM scrap WHERE (date > '$searchDate' AND journal = '$journal' AND (LOWER(teaser)LIKE LOWER('%{$topic}%') OR LOWER(title) LIKE LOWER('%{$topic}%'))) ORDER BY date DESC LIMIT $searchLimit) as tbl GROUP BY tbl.title";

$sql .= "INSERT INTO search_loggedin (date, journal, inputdate, searchlimit, topic) VALUES ('$date', '$journal', '$searchDate', '$searchLimit', '$topic')";

$dbc->multi_query($sql);

$res = $dbc->store_result();

echo $dbc->error;
  

未声明的变量:search_loggedin

我刚刚创建了search_loggedin表,但是我在另一张旧表上执行了完全相同的查询,但它确实有效。

为什么会出现此错误?

1 个答案:

答案 0 :(得分:0)

你的两个陈述需要用分号分隔:

$sql = "SELECT tbl.* FROM (SELECT date, section, title, teaser, href, image FROM scrap WHERE (date > '$searchDate' AND journal = '$journal' AND (LOWER(teaser)LIKE LOWER('%{$topic}%') OR LOWER(title) LIKE LOWER('%{$topic}%'))) ORDER BY date DESC LIMIT $searchLimit) as tbl GROUP BY tbl.title;";

虽然TBH - 您不应该使用多重查询,但最好一次做一件事!