Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in D:\wamp\www\Forum\forumregister.php on line 32
and this my code:

$conn=mysqli_connect("localhost","root","","cars");
$query=mysqli_query($conn,"select * from users where name='".$username."' ");
//////if the name doesnt exists //////////
	[B]if(mysqli_num_rows($query)==0){[/B]
		/////insert the data if not existed/////
		$query=mysqli_query($conn,"insert into users (name,password,email,showemail)
		values('".$username."',password('".$password."'),'".$email."','".$showemail."' )" );
			if($query){
				$logged_in_user=$username;
				session_register("logged_in_user");
		$query=musqli_query("select userID from users where name='".$username."'");
				if(!$query)fail("database query faild",true);
				$record=mysqli_fetch_assoc($query);
				$logged_userID=$record["userID"];
				session_register("logged_userID");



why????

    Because the number of rows returned only makes sense with a particular result set. However, for a SELECT query mysqli_query() can return a result resource (representing a result set) or false (a boolean). Consequently, you should check, e.g.,

    $conn = mysqli_connect("localhost", "root", "", "cars");
    if ($result = mysqli_query($conn, "select * from users where name='" . $username . "'")) {
        if (mysqli_num_rows($result) == 0) {
            /////insert the data if not existed/////
            // ...

    Incidentally, it is better to write:

    $conn = mysqli_connect("localhost", "root", "", "cars");
    if ($result = mysqli_query($conn, "SELECT COUNT(*) FROM users WHERE name='" . $username . "'")) {
        $row = $result->fetch_assoc();
        if ($row['COUNT(*)'] == 0) {
            /////insert the data if not existed/////
            // ...

    This way you only retrieve what you want. An even better way would be to attempt to insert the username. With the name column declared UNIQUE, the database server will report a UNIQUE constraint error that you can check for and thus handle.

      it gave me another error:
      and didnt solve the problem

      Fatal error: Call to a member function fetch_assoc() on a non-object in D:\wamp\www\Forum\forumregister.php on line 33

        Oh, I did not see that you were using the procedural form. Oh well, change:

        $row = $result->fetch_assoc();

        to

        $row = mysqli_fetch_assoc($result);

          well i solved it but have another one now
          thnxxx for trying to help

            am trying to make a valid login system
            but when i register a new account it works just fine but after and it tells me u logged in
            but when i log out and try to login in with the same username and password it tell me invalid match between username and password

              2 years later

              Fatal error: Call to undefined function mysql_num_rowsc() in C:\wamp\www\index.php on line 77

              <code>
              <head>
              <title>IsolatedStory</title>
              <style>
              { FONT-SIZE: 8pt; FONT-FAMILY: verdana; } b { FONT-WEIGHT: bold; } .listtitle { BACKGROUND: #425984; COLOR: #EEEEEE; white-space: nowrap; } td.list { BACKGROUND: #EEEEEE; white-space: nowrap; } </style>
              </head>
              <center><br><br><br><br>
              <h1>IsolatedStory</h1>
              <table cellspacing=1 cellpadding=5>
              <tr>
              <td class=listtitle colspan=2>Fill in the form below:</td></tr>
              <form action="register_do.php" method="POST">
              <tr><td class=list align=right>Username:</td><td class=list><input type=text name=name maxlength="30"></td></tr>
              <tr><td class=list align=right>Password:</td><td class=list><input type=password name=pass maxlength="30"></td></tr>
              <tr><td class=list align=right>PIN:</td><td class=list>
              <select name="pin1">
              <option value="0">0</option>
              <option SELECTED value="1">1</option>
              <option value="2">2</option>
              <option value="3">3</option>
              <option value="4">4</option>
              <option value="5">5</option>
              <option value="6">6</option>
              <option value="7">7</option>
              <option value="8">8</option>
              <option value="9">9</option>
              </select>
              <select name="pin2">
              <option value="0">0</option>
              <option value="1">1</option>
              <option SELECTED value="2">2</option>
              <option value="3">3</option>
              <option value="4">4</option>
              <option value="5">5</option>
              <option value="6">6</option>
              <option value="7">7</option>
              <option value="8">8</option>
              <option value="9">9</option>
              </select>
              <select name="pin3">
              <option value="0">0</option>
              <option value="1">1</option>
              <option value="2">2</option>
              <option SELECTED value="3">3</option>
              <option value="4">4</option>
              <option value="5">5</option>
              <option value="6">6</option>
              <option value="7">7</option>
              <option value="8">8</option>
              <option value="9">9</option>
              </select>
              <select name="pin4">
              <option value="0">0</option>
              <option value="1">1</option>
              <option value="2">2</option>
              <option value="3">3</option>
              <option SELECTED value="4">4</option>
              <option value="5">5</option>
              <option value="6">6</option>
              <option value="7">7</option>
              <option value="8">8</option>
              <option value="9">9</option>
              </select></td></tr>
              <tr><td class=list align=right>Gender:</td><td class=list>
              <select name="gender">
              <option value="0">Male</option>
              <option value="1">Female</option>
              </select>
              </td></tr>
              <tr><td class=listtitle align=right colspan=2><input type=submit name=submit value='Register'></td></tr>
              </form>
              </table>
              <br>
              <?php
              include('config.php');
              $result = mysql_query("SELECT
              FROM users", $db);// Account section
              $num_rows = mysql_num_rowsc($result);
              $result2 = mysql_query("SELECT * FROM characters", $db);// Character section
              $num_rowsc = mysql_num_rows($result2);
              echo 'Stats:<br><b> '.$num_rows.' </b> Accounts registered:<br><b> '.$num_rowsc.' </b> Characters created:';
              ?>
              </center></body></html></code

                That's because mysql_num_rowsc does not exist as a function. Spelling matters.

                  Write a Reply...