This question already has an answer here:
On line 25 in my code, I wrote this:
$check = mysql_num_rows($u_check);
and it gave me the error:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in D:\Download\htdocs\hoping.php on line 25
Here is my entire code of the file:
<?php include ("./header.inc.php"); ?>
<?php
$reg = @$_POST['reg'];
$fn = "";
$ln = "";
$un = "";
$em = "";
$em2 = "";
$pswd = "";
$pswd2 = "";
$d = "";
$u_check = "";
$fn = strip_tags(@$_POST['fname']);
$ln = strip_tags(@$_POST['lname']);
$un = strip_tags(@$_POST['username']);
$em = strip_tags(@$_POST['email']);
$em2 = strip_tags(@$_POST['email2']);
$pswd = strip_tags(@$_POST['password']);
$pswd2 = strip_tags(@$_POST['password2']);
$d = date("Y-m-d");
if($reg){
if($em==$em2){
$u_check = mysql_query("SELECT username FROM test WHERE username='$un'");
$check = mysql_num_rows($u_check);
if($check == 0){
if($fn&&$ln&&$un&&$em&&$em2&&$pswd&&$pswd2){
if($pswd==$pswd2){
if(strlen($un)>25||strlen($fn)>25||strlen($ln)>25){
echo "The maximum limit for username/first name/last name is 25 characters!";
}
else
{
if(strlen($pswd)>30||strlen($pswd)<5){
echo "Your password must be between 5 and 30 characters long!";
}
else
{
$pswd =md5($pswd);
$pswd2 = md5($pswd2);
$query = mysql_query("INSERT INTO test VALUES ('', '$un', '$fn', '$ln','$em', '$pswd', '$d','0')");
die("<h2>Welcome to communicate</h2>Login to your account to get started ...");
}
}
}
else {
echo "Your passwords don't match!";
}
}
else {
echo "Please fill in all of the fields";
}
}
else {
echo "Username already taken ...";
}
}
else {
echo "Your E-mails don't match!";
}
}
if(isset($_POST["user_login"]) && isset($_POST["password_login"])) {
$user_login = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["user_login"]);
$password_login = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password _login"]);
}
?>
<td width="40%">
<h2>Sign Up Below!</h2>
<form action="#" method="POST">
<input type="text" name="fname" size="25" placeholder="First Name" /><p />
<input type="text" name="lname" size="25" placeholder="Last Name"/><br /><br />
<input type="text" name="username" size="25" placeholder="Username"/><br /><br />
<input type="text" name="email" size="25" placeholder="Email Address"/><br /><br />
<input type="text" name="email2" size="25" placeholder="Email Address (again)"/><br /><br />
<input type="text" name="password" size="25" placeholder="Password"/><br /><br />
<input type="text" name="password2" size="25" placeholder="Password (again)"/><br /><br />
<input type="submit" name="reg" value="Sign Up!">
</td>
</tr>
</table>
<?php include ("./footer.inc.php"); ?>
Why is it giving me that error?
</div>