SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql_num_rows(): supplied argument is not a valid MySQL result resource

    Hi,

    Something is going on with my file. I am getting this error message:
    mysql_num_rows(): supplied argument is not a valid MySQL result resource

    This is the line of code that is causing the issue:
    if (mysql_num_rows($data) == 0) {

    Here is the full code:

    PHP Code:
    <html>

    <head>

    <link rel="stylesheet" type="text/css" href="style.css" />

    </head>

    <body>

    <div class="main-content">

    <div class="userhomecontainer">


    <div>
    <?php

      error_reporting
    (E_ALL);
    ini_set("display_errors"1);

      
    // Insert the page header
      
    $page_title 'Sign Up';
        require_once(
    'header.php');
      require_once(
    'appvars.php');
      require_once(
    'connectvars.php');
    ?>
    </div>

    <div style="clear: both;"></div>

    <?php 
      
    require_once('navmenu.php');
    ?>


    <?php

      
    // Connect to the database
      
    $dbc mysql_connect(DB_HOSTDB_USERDB_PASSWORDDB_NAME);

      if (isset(
    $_POST['submit'])) {
        
    // Grab the profile data from the POST
        
    $username mysql_real_escape_string(trim($_POST['username']), $dbc);
        
    $password1 mysql_real_escape_string(trim($_POST['password1']), $dbc);
        
    $password2 mysql_real_escape_string(trim($_POST['password2']), $dbc);

        if (!empty(
    $username) && !empty($password1) && !empty($password2) && ($password1 == $password2)) {
          
    // Make sure someone isn't already registered using this username
          
    $query "SELECT * FROM mismatch_user WHERE username = '$username'";
         
    error_reporting(E_ALL);
    ini_set("display_errors"1);      
          
    $data mysql_query($query$dbc);
          if (
    mysql_num_rows($data) == 0) {
            
    // The username is unique, so insert the data into the database
            
    $query "INSERT INTO mismatch_user (username, password, join_date) VALUES ('$username', SHA('$password1'), NOW())";
            
    mysql_query($query$dbc);

            
    // Confirm success with the user
            
    echo '<p>Your new account has been successfully created. You\'re now ready to <a href="login.php">log in</a>.</p>';

            
    mysql_close($dbc);
            exit();
          }
          else {
            
    // An account already exists for this username, so display an error message
            
    echo '<p class="error">An account already exists for this username. Please use a different address.</p>';
            
    $username "";
          }
        }
        else {
          echo 
    '<p class="error">You must enter all of the sign-up data, including the desired password twice.</p>';
        }
      }

      
    mysql_close($dbc);
    ?>




    <div style="text-align: center; margin: 0 auto; width: 500px; padding-top: 50px; padding-bottom: 30px;">
    <div class="registerlogin">
    <div style="padding-top: 50px;">
      <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <fieldset>
          <label for="username">Username:</label>
          <input type="text" id="username" name="username" value="<?php if (!empty($username)) echo $username?>" /><br />
          <label for="password1">Password:</label>
          <input type="password" id="password1" name="password1" /><br />
          <label for="password2">Password (retype):</label>
          <input type="password" id="password2" name="password2" /><br />
        </fieldset>
        <input type="submit" value="Sign Up" name="submit" />
      </form>
    </div>
    </div>
    </div>

      

    <?php
      
    // Insert the page footer
      
    require_once('footer.php');
    ?>

    </div>
    </div>
    Thanks!

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    153 Post(s)
    Tagged
    3 Thread(s)
    It means your query is failing.

    Add
    PHP Code:
     $data mysql_query($query$dbc) or die(mysql_error()); 
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where do I add this at?

  4. #4
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK. I added this.

    Now I get this message:

    "No database selected"

    Thoughts?

  5. #5
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mysql_connect()

    last value isn't selecting the database, check whether or not DB_NAME has a value

  6. #6
    SitePoint Zealot Kayarc's Avatar
    Join Date
    Sep 2009
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by RiemenDesign View Post
    OK. I added this.

    Now I get this message:

    "No database selected"

    Thoughts?


    try:
    PHP Code:
    echo DB_NAME/*is the DB_NAME set correctly? */
    $dbc mysql_connect(DB_HOSTDB_USERDB_PASSWORDDB_NAME); 
    Phoenix Arizona Web Design | info *at* kayarc.com | 602.633.2676

  7. #7
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by craqgerbil View Post
    mysql_connect()

    last value isn't selecting the database, check whether or not DB_NAME has a value
    Yeah. I use a file, connectvars.php for this.

    Here is that line:

    define('DB_NAME', 'mismatch');

  8. #8
    SitePoint Zealot Kayarc's Avatar
    Join Date
    Sep 2009
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by RiemenDesign View Post
    Yeah. I use a file, connectvars.php for this.

    Here is that line:

    define('DB_NAME', 'mismatch');
    One of the DB_ constants is wrong; it's got to be DB_NAME

    edit:
    actually
    PHP Code:
    <?php
    $dbc 
    mysql_connect(DB_HOSTDB_USERDB_PASSWORD); 
    mysql_select_db(DB_NAME,$dbc);
    ?>
    Phoenix Arizona Web Design | info *at* kayarc.com | 602.633.2676

  9. #9
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kayarc View Post
    One of the DB_ constants is wrong; it's got to be DB_NAME

    edit:
    actually
    PHP Code:
    <?php
    $dbc 
    mysql_connect(DB_HOSTDB_USERDB_PASSWORD); 
    mysql_select_db(DB_NAME,$dbc);
    ?>
    I appreciate your effort, but this did not work.

    Same error.

  10. #10
    SitePoint Zealot Kayarc's Avatar
    Join Date
    Sep 2009
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by RiemenDesign View Post
    I appreciate your effort, but this did not work.

    Same error.
    if you <?php echo DB_NAME; ?> does it give you the correct result?
    Phoenix Arizona Web Design | info *at* kayarc.com | 602.633.2676

  11. #11
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If all else fails, perhaps the user level you have chosen will not allow you to read the table.

    If you use PhpMyAdmin (PMA) to administer your database and you can see the table as expected, then take a look in config.php and check which credentials PMA is using.

    You could also try and temporarily hardcode the values into your database connector:

    mysql_select_db("real_name",$dbc);


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •