By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,940 Members | 1,391 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,940 IT Pros & Developers. It's quick & easy.

Warning: mysql_num_rows(): problem!!!

P: 9
Hi

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


Warning: mysql_fetch_array(): 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......

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $button = $_POST['button'];
  4.  
  5. if ($button)
  6. {
  7.     // get data
  8.     $username = $_POST['username'];
  9.     $password = $_POST['password'];
  10.     $retypepassword = $_POST['retypepassword'];
  11.     $email = $_POST['email'];
  12.  
  13.     if($username && $password && $retypepassword && $email)
  14.     {
  15.         if ($password == $retypepassword)
  16.         {
  17.             if(substr( "@", $email) && substr(".", $email))
  18.             {
  19.                 include("connect.php");
  20.                 $query = mysql_query("SELECT * FROM username WHERE username='$username'");
  21.                 $numrows = mysql_num_rows($query);
  22.                 if ($numrows == 0)
  23.                 {
  24.                 $password = md5($password);
  25.  
  26.                 $register = mysql_query("INSERT INTO users ()");
  27.                 }
  28.                 else
  29.                 echo "The username is taken.";
  30.             }
  31.             else
  32.                 echo "Not a valid email";
  33.         }
  34.     }
  35.     else
  36.         echo "You did not fill in every field.";
  37. }
  38. else
  39. {
  40.     echo '<form action="register.php" method="POST">
  41.         <table width="300">
  42.         <tr>
  43.             <td align="right">Username</td>
  44.             <td align="left"><input type="text" name="username"></td>
  45.         </tr>
  46.         <tr>
  47.             <td align="right">Password</td>
  48.             <td align="left"><input type="password" name="password"></td>
  49.         </tr>
  50.         <tr>
  51.             <td align="right">Retype password</td>
  52.             <td align="left"><input type="password" name="retypepassword"></td>
  53.         </tr>
  54.         <tr>
  55.             <td align="right">Email</td>
  56.             <td align="left"><input type="text" name="email"></td>
  57.         </tr>
  58.         <tr>
  59.             <td align="right"></td>
  60.             <td align="left"><input type="submit" name="button" value="Register"></td>
  61.         </tr>
  62.         </table>
  63.         </form>';
  64. }
  65.  
  66.  
  67. ?>
Apr 20 '10 #1
Share this Question
Share on Google+
7 Replies


Markus
Expert 5K+
P: 6,050
Please see this article by Atli.

Also, please, in future, use [code] tags when posting code.
Apr 20 '10 #2

P: 9
mhh.. I am very new to this..I still dont understand?
Apr 20 '10 #3

Markus
Expert 5K+
P: 6,050
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().
Apr 20 '10 #4

P: 9
I am still lost
Apr 20 '10 #5

P: 9
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


Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $button = $_POST['button'];
  4.  
  5. if ($button)
  6. {
  7.     // get data
  8.     $username = $_POST['username'];
  9.     $password = $_POST['password'];
  10.     $retypepassword = $_POST['retypepassword'];
  11.     $email = $_POST['email'];
  12.  
  13.     if($username && $password && $retypepassword && $email)
  14.     {
  15.         if ($password == $retypepassword)
  16.         {
  17.             if(substr( "@", $email) && substr(".", $email))
  18.             {
  19.                 include("connect.php");
  20.                 $query = mysql_query("SELECT * FROM username WHERE username='$username'");
  21.                 $numrows = mysql_num_rows($query);
  22.                 if ($numrows == 0)
  23.                 {
  24.                 $password = md5($password);
  25.  
  26.                 $register = mysql_query("INSERT INTO users VALUES ('', '$username', '$password', 'retypepassword', 'email')");
  27.  
  28.                 echo "You have been registered.";
  29.  
  30.                 }
Apr 21 '10 #6

Atli
Expert 5K+
P: 5,058
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.
Apr 21 '10 #7

P: 9
Thanks.. I got it working now;)
Apr 25 '10 #8

Post your reply

Sign in to post your reply or Sign up for a free account.