查询无法正确插入时出现问题。
当我有线
mysqli_query($GLOBALS["___mysqli_ston"], "INSERT INTO emailerdata (`emailer_timestamp`,`emailer_promoID`,`emailer_name`,`emailer_username`,`emailer_usermd5`,`emailer_email`,`emailer_md5`,`emailer_reactionID`) VALUES ('$date','$promoID','$rec_info[2]','$row[1]','$usermd5','$rec_info[0]','$passmd5','$row[0]')") or die("Error: ". ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)). " with query ". mysqli_query);
在它上面,它插入正常。但是,当我尝试检查我的数据库中的电子邮件地址是否已在查询中插入了该特定促销ID时,它不会插入。
我无法找到查询的错误,我确定它的内容很简单,但它不会显示错误或死亡?
$row_amt = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * from emailerdata where emailer_promoID='$promoID' and emailer_username='$downloadusername'");
while($row4 !== mysqli_fetch_assoc($row_amt)) {
mysqli_query($GLOBALS["___mysqli_ston"], "INSERT INTO emailerdata (`emailer_timestamp`,`emailer_promoID`,`emailer_name`,`emailer_username`,`emailer_usermd5`,`emailer_email`,`emailer_md5`,`emailer_reactionID`) VALUES ('$date','$promoID','$rec_info[2]','$row[1]','$usermd5','$rec_info[0]','$passmd5','$row[0]')") or die("Error: ". ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)). " with query ". mysqli_query);
}
非常感谢!
答案 0 :(得分:0)
使用函数mysqli_num_rows检查按查询返回的行数
$row_amt = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * from emailerdata where emailer_promoID='$promoID' and emailer_username='$downloadusername'");
$rowcount=mysqli_num_rows($row_amt);
if($rowcount == 0) {
mysqli_query($GLOBALS["___mysqli_ston"], "INSERT INTO emailerdata (`emailer_timestamp`,`emailer_promoID`,`emailer_name`,`emailer_username`,`emailer_usermd5`,`emailer_email`,`emailer_md5`,`emailer_reactionID`) VALUES ('$date','$promoID','$rec_info[2]','$row[1]','$usermd5','$rec_info[0]','$passmd5','$row[0]')") or die("Error: ". ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)). " with query ". mysqli_query);
}else{
echo 'Email is already registered.';
}