www.webdeveloper.com
Results 1 to 2 of 2

Thread: Help with User Logins

  1. #1
    Join Date
    Dec 2011
    Posts
    55

    Help with User Logins

    I'm looking at various resources in order to understand how to create user logins for a website, but every time I try something goes wrong. Specifically...well below is my code, where specifically this line "$numrows = mysql_num_rows($query);" gives me the error "Warning: mysqli_stmt_num_rows() expects parameter 1 to be mysqli_stmt, string given" and I have no clue how to fix this. If someone could help it'd be greatly appreciated. Connection to the database works fine, it's that one line though that gives me grief.

    Code:
    $myusername = $_POST['username'];
    	$mypassword = $_POST['pass'];
    	
    	if ($myusername && $mypassword) {
    	$connection = @new mysqli($host, $username, $password, $db_name);
    	if ($connection->connect_error) {
    		die('Connect Error' . $connection->connect_error);
    	} else {
    		echo 'Successfully Connected to the Database';
    		
    		$query = "SELECT * FROM logins WHERE username = '$username'";
    		
    		$numrows = mysql_num_rows($query);
    		
    		if ($numrows !=0) {
    			while($rows = mysql_fetch_assoc($query)) {
    				$db_username = $row['username'];
    				$db_password = $row['password'];
    			}
    			
    			if ($myusername == $db_username && $mypassword == $db_password) {
    				echo "Login Successful";
    			} else {
    				echo "The username and/or password were incorrect";
    			}
    			
    		}
    	}
    	}

  2. #2
    Join Date
    Jul 2003
    Location
    Lansdale, PA
    Posts
    88
    You forgot to run:

    PHP Code:
    $result mysql_query($query); 
    then call mysql_num_rows on $result.

    -Jim

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles