Warning: mysql_num_rows(): problem!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hotmodi
    New Member
    • Apr 2010
    • 9

    Warning: mysql_num_rows(): problem!!!

    Hi

    Can somebody please help me out;) I keep getting this error,


    Warning: mysql_fetch_arr ay(): supplied argument is not a valid MySQL result resource in /usr/home/moari3/public_html/Opretbruger/register.php on line 21


    This is my code......

    Code:
    <?php
    
    $button = $_POST['button'];
    
    if ($button)
    {
    	// get data
    	$username = $_POST['username'];
    	$password = $_POST['password'];
    	$retypepassword = $_POST['retypepassword'];
    	$email = $_POST['email'];
    	
    	if($username && $password && $retypepassword && $email)
    	{
    		if ($password == $retypepassword)
    		{
    			if(substr( "@", $email) && substr(".", $email))
    			{
    				include("connect.php");
    				$query = mysql_query("SELECT * FROM username WHERE username='$username'");
    				$numrows = mysql_num_rows($query);
    				if ($numrows == 0)
    				{
    				$password = md5($password);
    				
    				$register = mysql_query("INSERT INTO users ()");
    				}
    				else
    				echo "The username is taken.";
    			}
    			else
    				echo "Not a valid email";
    		}
    	}
    	else
    		echo "You did not fill in every field.";
    }
    else
    {
    	echo '<form action="register.php" method="POST">
            <table width="300">
            <tr>
                <td align="right">Username</td>
                <td align="left"><input type="text" name="username"></td>
            </tr>
            <tr>
                <td align="right">Password</td>
                <td align="left"><input type="password" name="password"></td>
            </tr>
            <tr>
                <td align="right">Retype password</td>
                <td align="left"><input type="password" name="retypepassword"></td>
            </tr>
            <tr>
                <td align="right">Email</td>
                <td align="left"><input type="text" name="email"></td>
            </tr>
            <tr>
                <td align="right"></td>
                <td align="left"><input type="submit" name="button" value="Register"></td>
            </tr>
            </table>
            </form>';
    }
    
    
    ?>
    Last edited by Markus; Apr 20 '10, 12:26 PM. Reason: Added [code] tags
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Please see this article by Atli.

    Also, please, in future, use [code] tags when posting code.

    Comment

    • hotmodi
      New Member
      • Apr 2010
      • 9

      #3
      mhh.. I am very new to this..I still dont understand?

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Look at the "How Do I Fix It?" bit. All the information you need is there. More specifically: checking the return value of your mysql_query() call, and also the use of mysql_error().

        Comment

        • hotmodi
          New Member
          • Apr 2010
          • 9

          #5
          I am still lost

          Comment

          • hotmodi
            New Member
            • Apr 2010
            • 9

            #6
            Can somebody please help me out;)

            keep getting this error:

            Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in /usr/home/moari3/public_html/Opretbruger/register.php on line 21


            Code:
            <?php
            
            $button = $_POST['button'];
            
            if ($button)
            {
            	// get data
            	$username = $_POST['username'];
            	$password = $_POST['password'];
            	$retypepassword = $_POST['retypepassword'];
            	$email = $_POST['email'];
            	
            	if($username && $password && $retypepassword && $email)
            	{
            		if ($password == $retypepassword)
            		{
            			if(substr( "@", $email) && substr(".", $email))
            			{
            				include("connect.php");
            				$query = mysql_query("SELECT * FROM username WHERE username='$username'");
            				$numrows = mysql_num_rows($query);
            				if ($numrows == 0)
            				{
            				$password = md5($password);
            				
            				$register = mysql_query("INSERT INTO users VALUES ('', '$username', '$password', 'retypepassword', 'email')");
            				
            				echo "You have been registered.";
            				
            				}
            Last edited by Atli; Apr 21 '10, 11:02 AM. Reason: Added [code] tags.

            Comment

            • Atli
              Recognized Expert Expert
              • Nov 2006
              • 5062

              #7
              Hey.

              Compare line #8 in the last example of the article with line #20 in your code.
              Additionally, compare the same line in your code with the second example of the Turn On PHP Debugging Messages sticky.

              See the what your line is missing?

              It's a common mistake (hence, the name of the article). You forget to verify that the query was successfully run, so when you try to use the result, it fails.

              Comment

              • hotmodi
                New Member
                • Apr 2010
                • 9

                #8
                Thanks.. I got it working now;)

                Comment

                Working...