[英]mysql select query result is null so how can i return default value in php
Facing the following error 面对以下错误
Error: Notice: Undefined index: id in /Applications/XAMPP/xamppfiles/htdocs/mks/opencart-1.5.6.1/upload/admin/controller/catalog/vendhqbridge.php on line 120
错误:注意:未定义索引:120行/Applications/XAMPP/xamppfiles/htdocs/mks/opencart-1.5.6.1/upload/admin/controller/catalog/vendhqbridge.php中的ID
Relevant code: 相关代码:
//check for existing 'VendHQ_id' on DB's product table
function checkVendHQid($flagChk)
{
$rs = $this->db->query("SELECT vendhq_id as id FROM ".DB_PREFIX."vendhq_product WHERE vendhq_id = '".$flagChk."'");
$rowRsl=-1;
if($rs===null)
{
$rowRsl = -1;
}
else
{
if($rs->row["id"] == $flagChk )
{
$rowRsl = 1;
}
}
return $rowRsl;
}
在FROM
之后放置一个空格
$rs = $this->db->query("SELECT vendhq_id as id FROM ".DB_PREFIX."vendhq_product WHERE vendhq_id = '".$flagChk."'");
As mentioned by Vikas Umrao and shadyyx, you should change the query and the if condition as below: 如Vikas Umrao和shadyyx所述,您应该更改查询和if条件,如下所示:
Change: 更改:
$rs = $this->db->query("SELECT vendhq_id as id FROM ".DB_PREFIX."vendhq_product WHERE vendhq_id = '".$flagChk."'");
$rowRsl=-1;
if($rs===null)
To: 至:
$rs = $this->db->query("SELECT vendhq_id as id FROM ".DB_PREFIX."vendhq_product WHERE vendhq_id = '".$this->db->escape($flagChk)."'");
$rowRsl=-1;
if(!$rs->num_rows){
Have a nice day !! 祝你今天愉快 !!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.