所以问题是 $check 变量始终为 NULL,即使数据库中已经有一条记录与我编写的 SELECT 语句匹配,它仍然为空。我知道这很简单,但我找不到错误。我已经尝试过使用空、isNull、====,但问题是 $check 始终为空。为什么它总是为空?
$sql = "SELECT * FROM linkedin_lookup WHERE "
."`given-name`='{$table['given_name']}' && "
."`family-name`='{$table['family_name']}' && "
."`location`='{$table['location']}' && "
."`industry`='{$table['industry']}' && "
."`headline`='{$table['headline']}'";
$results = $db->query($sql);
$check = $results->num_rows;
if ($check):
echo "Record already exist";
else:
$sql = "INSERT INTO linkedin_lookup (`given-name`,`family-name`,`location`,`industry`,`headline`,`date_search`) "
."VALUES "
."('{$table['given_name']}',"
."'{$table['family_name']}',"
."'{$table['location']}',"
."'{$table['industry']}',"
."'{$table['headline']}',"
."'{$now}')";
$db->query($sql);
echo "Succesfully inserted record(s)" . '<br />';
endif;
更新我的代码以反映输入,但它仍然接受重复。我的选择语句错了吗?我把 && 放对了,所以它应该扫描所有字段,如果相同的话。