我在$count
部分收到错误,以验证数据是否存在,
它说那个
它返回布尔值
但我不明白为什么。我已对错误所在的哪一行发表评论。
$check = mysql_fetch_array(mysql_query("SELECT * FROM `request` WHERE `Request_ID`=''"));
$count = mysql_num_rows($check); // error is here
if($count > 0){
?>
<script>
alert('Data Already Exist!');
</script>
<?php
}else{
mysql_query("INSERT INTO `request` (`Request_Name`, `Request_Date`, `Request_By`,`Description`,`Quantity`, `Price`, `Destination`,`Reason`) VALUES ('$name', '$date', '$req','$desc','$qty','$prc','$dest','$reason',)");
?>
<script>
window.location = "home.php#requi.php";
</script>
<?php
}
}
如何解决这个问题?
答案 0 :(得分:1)
您只能在结果对象上调用mysql_num_rows
。
如果要获取结果的num行,则必须使用以下代码:
$check = mysql_query("SELECT * FROM `request` WHERE `Request_ID`=''");
$count = mysql_num_rows($check); // error should be gone
//Optional:
while($data = mysql_fetch_array($check, MYSQLI_ASSOC))
{
$result[] = $data;//To get all rows, one by one
}
另外请注意我不建议使用mysql,而是使用mysqli,如果您需要帮助,我将很乐意为您提供进一步帮助。
答案 1 :(得分:0)
尝试使用mysql_num_rows()
替换mysql_fetch_array()
。
检查参考here。
答案 2 :(得分:0)
mysql_fetch_array:
@IBAction func loginAction(sender: AnyObject) {
let email = textEmail.text
let password = textPassword.text
spinnerInitialization()
startSpinner()
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.loginRequest(email!, password: password!)
}
func spinnerInitialization(){
spinnerView = UIView(frame: CGRect(x:0, y:0,width: 250,height: 50))
spinnerView.backgroundColor = UIColor.blackColor()
spinnerView.layer.cornerRadius = 10
let wait = UIActivityIndicatorView(frame: CGRect(x:0,y: 0,width: 50,height: 50))
wait.color = UIColor.whiteColor()
wait.hidesWhenStopped = false
wait.startAnimating()
let text = UILabel(frame: CGRect(x:60,y:0,width:200,height: 50))
text.textColor = UIColor.whiteColor()
text.text = "Please wait..."
spinnerView.addSubview(wait)
spinnerView.addSubview(text)
spinnerView.center = self.view.center
spinnerView.tag = 1000
}
func startSpinner(){
view.addSubview(spinnerView)
}
func stopSpinner(){
let subViews = view.subviews
for subView in subViews{
if subView.tag == 1000{
subView.removeFromSuperview()
}
}
}
我的猜测是它返回false。这就是你得到错误的原因。