PHP help needed

I am getting this error in my script: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in E:\Server\SERVER\root\regcheck.php on line 46
And here is my code:
[php]

<?php include("./header.html"); ?>


<?php if( isset( $_POST['user'] ) && isset( $_POST['pass'] ) && isset( $_POST['email']) && isset( $_POST['age'] ) ) { if( strlen( $_POST['user'] ) < 3 ) { echo "Username Must Be More Than 3 Characters."; } elseif( strlen( $_POST['pass'] ) < 4 ) { echo "Password Must Be More Than 4 Characters."; } elseif( strlen( $_POST['email'] ) < 1 ) { echo "Email must be Valid"; } elseif( strlen( $_POST['age'] ) ) { echo "You must be 13 years of age or older."; } elseif( $_POST['pass'] == $_POST['user'] ) { echo"Username And Password Can Not Be The Same. Security risks."; } else { include( 'database.php' );

$email = mysql_real_escape_string( $_POST[‘email’] );
$age = mysql_real_escape_string( $_POST[‘age’] );
$username = mysql_real_escape_string( $_POST[‘user’] );
$password = md5( $_POST[‘pass’] );
//Error area
$sqlcheckforduplicate = “SELECT username FROM members WHERE username = '”. $username ."’";

if ( mysql_num_rows( mysql_query( ‘sqlcheckforduplicate’ ) ) == 0 )
{
$sqlRegUser = “INSERT INTO
members( email, age, username, password )
VALUES(
'”. $email ."’,
‘". $age ."’,
‘". $username ."’,
‘". $password ."’
)";
// End error area
if( !mysql_query( $sqlRegUser ) )
{
echo “You Could Not Register Because Of An Unexpected Error.”;
}
else
{
echo “You Are Registered And Can Now Login”;
$formUsername = $username;

header (‘location: register_success.php’);
}
}
else
{
echo “The Username You Have Chosen Is Already Being Used By Another User. Please Try Another One.”;
$formUsername = $username;
}
}
}
else
{
echo “You Could Not Be Registered Because Of Missing Data.”;
}
?>

<?php include("./footer.html"); ?>
[/php]

Can anybody help me?

[php]
if ( mysql_num_rows( mysql_query( ‘sqlcheckforduplicate’ ) ) == 0 )
[/php]
is the mistake you are missing the dollar sign to make the variable

[php]
if ( mysql_num_rows( mysql_query( ‘$sqlcheckforduplicate’ ) ) == 0 )
[/php]

But that does not fix my problem, I get the same error when making an account.

Try changing this:
if ( mysql_num_rows( mysql_query( ‘sqlcheckforduplicate’ ) ) == 0 )

To this:
[php]
if ( mysql_num_rows( mysql_query( $sqlcheckforduplicate ) ) == 0 )
[/php]
It’s a variable, so say so, it is not a TEXT query…

Like I said before, I GET THE SAME ERROR! >:(

Well, do this:
Just BEFORE that line:

echo $sqlcheckforduplicate;

OR, even die($sqlcheckforduplicate);

That would display what this QUERY really is and see if it is acurate.
Another thing, is you normally do query’s and row counts this way:

$query=“some query”;
$results=mysql_query($query) or die(“bad query”);
if (mysql_num_rows($results)==0)
or
if(!$results) (same thing)

So, maybe it is dropping pass your num-rows somehow…
I would check you actual query first and see if it is working…
(Good luck, I will be here most of the night to help if you need more…)

wont work, I can’t get it to work.

Well, help us help you!

If line #46 is causing you an error, then, display the variables used in that line and show us them.
It is most likely that you are just setting up a variable wrong or using that variable wrong.
Your code can work if you just DEBUG it correctly.

If you show us bad code, you have to fix that before we can find more bad code. Telling us that is doesn’t work doesn’t help us help you. Tell us WHY it doesn’t work and what errors you are getting now. And, the line numbers and which line the bad one is and what is inside your variables at the time of the error.

More info, please, if you want to solve this!

Sponsor our Newsletter | Privacy Policy | Terms of Service