我正在使用以下对我不起作用的代码。
$con=mysqli_connect("localhost","root","","my_db"); $check="SELECT COUNT(*) FROM persons WHERE Email = '$_POST[eMailTxt]'"; if (mysqli_query($con,$check)>=1) { echo "User Already in Exists<br/>"; } else { $newUser="INSERT INTO persons(Email,FirstName,LastName,PassWord) values('$_POST[eMailTxt]','$_POST[NameTxt]','$_POST[LnameTxt]','$_POST[passWordTxt]')"; if (mysqli_query($con,$newUser)) { echo "You are now registered<br/>"; } else { echo "Error adding user in database<br/>"; } }
无法在 C:\ xampp \ htdocs \ Exp \ welcome.php 中将mysqli_result类的对象转换为int
该代码对您来说很好…
$con=mysqli_connect("localhost","root","","my_db"); $check="SELECT * FROM persons WHERE Email = '$_POST[eMailTxt]'"; $rs = mysqli_query($con,$check); $data = mysqli_fetch_array($rs, MYSQLI_NUM); if($data[0] > 1) { echo "User Already in Exists<br/>"; } else { $newUser="INSERT INTO persons(Email,FirstName,LastName,PassWord) values('$_POST[eMailTxt]','$_POST[NameTxt]','$_POST[LnameTxt]','$_POST[passWordTxt]')"; if (mysqli_query($con,$newUser)) { echo "You are now registered<br/>"; } else { echo "Error adding user in database<br/>"; } }