473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Warning: mysql_num_rows(): problem!!!

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
7 2171
Markus
6,050 Expert 4TB
Please see this article by Atli.

Also, please, in future, use [code] tags when posting code.
Apr 20 '10 #2
mhh.. I am very new to this..I still dont understand?
Apr 20 '10 #3
Markus
6,050 Expert 4TB
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
I am still lost
Apr 20 '10 #5
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
5,058 Expert 4TB
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
Thanks.. I got it working now;)
Apr 25 '10 #8

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

Similar topics

1
by: smsabu2002 | last post by:
Hi, I am facing the build problem while installing the DBD-MySql perl module (ver 2.9008) using both GCC and CC compilers in HP-UX machine. For the Build using GCC, the compiler error is...
8
by: Michael L. Hostbaek | last post by:
Hi, I am trying to compile a piece of software, on a FreeBSD system. gcc version 2.95.4 When compiling, I get lots of these warnings: --- logger.c: In function `cf_logger_init':
3
by: DJTN | last post by:
I'm getting the following error when I try to compile my setup project in VS 2002. I have re-installed the .net framework 1.1 and it didnt solve the problem. WARNING: Unable to find dependency...
0
by: Thomas G. Apostolou | last post by:
Hello all. i am trying to make some win32 binaries of M2Crypto 0.15 What I use is: Python 2.3.3 openssl-0.9.7i swigwin 1.3.27
1
by: spanov | last post by:
i've got problem installing python-2.3.5 from sources on FreeBSD 5.3 root@server# ./configure > conf_log configure: WARNING: curses.h: present but cannot be compiled configure: WARNING:...
3
by: Chuck Cobb | last post by:
I'm doing a CSharp project in VS2005 and I'm getting some strange warning messages. The problem is that the warning messages don't link to anything in my code so they are very difficult to track...
0
by: Larry Lard | last post by:
This came out of a thread explaining to "BK" about error BC42025 ("Access of shared member through an instance; qualifying expression will not be evaluated"); Frans Clasener then came up with...
5
by: Peter Ritchie [C# MVP] | last post by:
I've purposely been ignoring a CA2122 warning in some C++ interop code I've been working on for quite some time. I've just recently had the cycles to investigate the warning. The warning message...
1
by: speralta | last post by:
For some reason the text in h2 tag is displaying as white in IE. http://www.salperalta.com/ <td class="sidebar" id="sidebar-right"> <div class="block block-listing" id="block-listing-0">...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.