...

View Full Version : Warning on mysql_num_rows!



angelali
02-25-2012, 08:19 PM
I created a registration form nd I have perfromed a check to see if the email address and the username already exist.

Here are my codes:


<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {

if (isset($_POST['fname']) && isset($_POST['lname'])&& isset($_POST['emailr']) && isset($_POST['user']) && isset($_POST['pass'])) {
//Assignng variables
$firstname = mysql_real_escape_string(stripslashes($_POST['fname']));
$lastname = mysql_real_escape_string(stripslashes($_POST['lname']));
$email = mysql_real_escape_string(stripslashes($_POST['emailr']));
$uname = mysql_real_escape_string(stripslashes($_POST['user']));
$pwd = mysql_real_escape_string(stripslashes($_POST['pass']));
$pmd= md5($pwd);
//Database
$connect = mysql_connect('localhost', 'root', '') or die ('Connection Failed');
mysql_select_db('registration', $connect) or die ('Connection Failed');

//Registration codes

if (empty($firstname) || empty($lastname) || empty($email) || empty($uname) || empty($pmd)) {
echo '<p class="error">All fields are required to fill!</p>';
return false;
} elseif (strlen($firstname) && (strlen($lastname) < '2')) {
echo '<p class="error">Invalid first name or last name!</p>';
return false;
} elseif (filter_var($firstname, FILTER_VALIDATE_INT) || (filter_var($lastname, FILTER_VALIDATE_INT))) {
echo '<p class="error">First name or last name cannot be integers!</p>';
return false;
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo '<p class="error">Email address not valid!</p>';
return false;
} elseif (strlen($uname) && (strlen($pmd) < '6' )) {
echo '<p class="error">Username or password must be minimum 6 characters!</p>';
return false;
} else {
$verify = "SELECT * FROM login WHERE emailaddress = '$email' AND username = '$uname'";
if(mysql_num_rows($verify) !== 0)
{
echo '<p class="fail">This email or username is already taken!</p>';
} else {
$query = "INSERT INTO login (id, firstname, lastname, emailaddress, username, password) VALUES('', '$firstname', '$lastname', '$email', '$uname', '$pmd')";
mysql_query($query, $connect);
echo '<p class="fail">Successful!</p>';
}
}
}
}
?>

The codes are working, and the check is being performed, but I am getting this warning:

Warning: mysql_num_rows() expects parameter 1 to be resource, string given in C:\xampp\htdocs\miniimagehosting\register.php on line 61

Why?

chose
02-25-2012, 08:27 PM
...
$verify = "SELECT * FROM login WHERE emailaddress = '$email' AND username = '$uname'";
if(mysql_num_rows($verify) !== 0)
...


mysql_num_rows() should have a mysq result, not raw sql



...
$verify = "SELECT * FROM login WHERE emailaddress = '$email' AND username = '$uname'";

//e.q
$result = mysql_query($verify);

if(mysql_num_rows($result) !== 0)
...

angelali
02-25-2012, 08:34 PM
I tried but does not work..it is still registering....

chose
02-25-2012, 08:42 PM
This code which you have posted has 46 lines, but you get error on 61.
Did you post right file ?

angelali
02-25-2012, 08:44 PM
because the rest of the codes above are HTML..

chose
02-25-2012, 09:19 PM
are you still getting this error when you use mysql_query($verify) ?

litebearer
02-25-2012, 09:32 PM
mysql_real_escape_string must be done AFTER connecting to the database



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum