Jump to content

Log in script blank page


Finker92

Recommended Posts

Hi, I created the login page below. However, when I enter details on the form I am getting a blank page. I can't figure out what is wrong. Any help/suggestions really welcome. Thanks in advance.

<html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>LOGIN FUNCTION</title>
</head>
<body>
<?php

require('connection.php');

if(empty($_POST['name'])){
$name=NULL;
echo "Sorry, you forgot to enter your username.</br>";
}else{
$name=@mysqli_real_escape_string($connection, trim($_POST['name']));
}	
if(empty($_POST['password'])){
$password=NULL;
echo "Sorry, you forgot to enter a password.</br>";
}else{ 
$password=@mysqli_real_escape_string($connection, trim($_POST['password']));
}
if(($name) && ($password)){
$info = "SELECT * FROM users WHERE username=$name and password=$password";
$return=@mysqli_query($connection, $info);

$count_rows=@mysqli_num_rows($return);
if($count_rows==1){	
session_start();
if(isset($_SESSION['login'])){
header("Location:admin.php");
}else{	
header("Location:login_fail.php");
}
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/254543-log-in-script-blank-page/
Share on other sites

Thanks, took them off and now I am getting this error

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean

I think this may be down to having the $connection in my query???? but when I remove it then I get two errors:

mysqli_query() expects parameter 1 to be mysqli, string

and

mysqli_num_rows() expects parameter 1 to be mysqli_result, null given.

The mysqli functions require the connection link in them.

 

Literal string data values in the query statement require single quotes around them.

 

To troubleshoot why your query is failing, you need to use mysqli_error($connection) to get mysql/php to tell you why. Use the following for your mysqli_query statement -

 

$return=mysqli_query($connection, $info) or die(mysqli_error($connection));

 

 

 

 

OK, I swapped the positions of the $connection and $info variables in the query and was getting no errors but blank page. Then I added the code you kindly gave me and I get the same result - now I am just getting a blank page with no errors but the code is not working because the url is still the same. Maybe there is something wrong with how I am setting the $SESSION??

The position of the connection link in the mysqli_query statement should have always been the first parameter, like you had in your first post in this thread. Randomly trying things in programming, isn't programming. It just wastes a huge amount of time. Programming languages are one of the most heavily documented subjects on the planet, because you need to read and understand the documentation for each statement that you are using, before you can effectively use each statement.

 

Your current code is not setting (assigning a value) to a session variable. Play computer and step through your logic, line by line, and make sure your logic is doing what you have defined you want it to do for each possible conditional branch.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.