您好,我想尝试检查ID是否存在,我应该在if语句上放些什么,我希望它仅检查并插入数据库中是否不存在,然后插入。如果存在的话,什么也不做。
function exists($date_, $account, $dimension)
{
$sql = "SELECT account FROM ".TB_PREF."budget WHERE account=".db_escape($account)
." AND tran_date='$date_' AND
id=".db_escape($dimension)." AND
$result = db_query($sql, "Cannot retreive transaction");
return (db_num_rows($result) > 0);
}
function add($date_, $account, $dimension, $dimension2, $amount)
{
$date = date2sql($date_);
if (exists_gl_budget($date, $account, $dimension, $dimension2))
else
$sql = "INSERT INTO ".TB_PREF."budget(tran_date,
account, id) VALUES ('$date',
".db_escape($account).", ".db_escape($dimension).", "
.db_escape($dimension2).", ".db_escape($amount).", '')";
db_query($sql, " not be saved");
}