这是完整的错误
警告:mysql_num_rows()期望参数1为资源,在第35行的C:\\ xampp \\ Installations \\ htdocs \\ finished \\ register.php中给出布尔值用户名已存在查询为空
这是我的代码:
//Checks to make sure the submit button is pressed
if (isset($_POST['submit'])){
$errors = array();
$valid = true;
//Checks to make sure the password meets the rules of validation
if(isset($_POST['Password'])) {
if(!preg_match('/^(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/',$_POST['Password'])) {
$errors ['Password'] = "Your password must have the following criteria - contain at least (1) upper case letter - contain at least (1) lower case letter - contain at least (1) number or special character - contain at least (8) characters in length";
echo $errors ['Password'];
$valid = false;
}
}
//Checks to make sure the email meets the rules of validation
if(isset($_POST['Email'])) {
if(!preg_match('/^([a-zA-Z0-9._-])+@[a-zA-Z0-9._-]+.([a-zA-Z]{2,4})$/',$_POST['Email'])) {
$errors['Email'] = "Must be valid email address";
echo $errors['Email'];
$valid = false;
}
}
if(empty($errors)) {
//This creates the connection to the database
$con = mysql_connect("localhost", "Peter", "password");
if(!$con) {
die("Can not connect:" . mysql_error());
}
//Selects the database I wish to add the table into
mysql_select_db("deepseadiving",$con);
//Passes the entered information into the table called user
$mysql=mysql_query("SELECT FROM User (Username) WHERE Username = '$_POST[Username]'");
if(mysql_num_rows($mysql)>=0)
{
echo"Username already exists";
}
else
{
$sql = "INSERT INTO User (Username,Password,FirstName,LastName,Email,Address,ContactNumber) VALUES('$_POST[Username]','$_POST[Password]','$_POST[FirstName]','$_POST[LastName]','$_POST[Email]','$_POST[Address]','$_POST[ContactNumber]')";
header("location:register.php");
}
mysql_query($mysql,$con) or die(mysql_error($con));
mysql_close($con);
}
}
?>