出於某種原因,我的else語句沒有觸發,我認爲我的方法由於某種原因沒有返回true。返回true不返回或我的其他表述不起作用?
主代碼
function msg($content)
{
//function that echos out page with content in it
}
$car=new yamiko_car;
if(!$car->add())//returns bool false on fail and true on success
{msg($car->error);}
else{msg('Car has been added');}
,並沒有也返回上失敗錯誤在那裏我測試數據,但只是把評論有方法。已經測試過它,它工作正常。
public function add()
{
//gets data succesfully
//MySQL
$this->query("INSERT INTO car (year, make, model, price, obo, img1, img2, img3, img4, description)
VALUES ('$year', '$make', '$model', '$price', '$obo', '$img1', '$img2', '$img3', '$img4', 'txt') ");
echo 'mysql added';
return true;
}
function query($sql, $result=false)
{
$query=mysql_query($sql);
if(!$query){$this->mysqlError.=mysql_error().'<br />';return false;}
if($result==false){return true;}
else{return $query;}
}
我加echo語句,並觸發精...
時,有它返回false錯誤和運行msg()
我切換語句if($car->add()){msg('car added')}else{msg($car->error);}
無論是如果或else語句會觸發
此外,if語句之後的任何代碼都不會觸發,並且不存在php或mysql錯誤。
你的附加功能返回TRUE每次 – 2012-02-29 13:11:49
'回報BOOL FALSE的失敗,真正的success'我沒有看到當它可能返回FALSE – 2012-02-29 13:12:09
不,它不會將註釋放在那裏,而不是顯示獲取和測試數據的所有代碼。 – Yamiko 2012-02-29 13:13:26