Thursday 20 September 2018

php - database not read from mysql database

my login page doesnt redirect me to the next webpage even if i inputted correct data on username and password.



when i check the config.inc and made it to config.php



it doesnt displays anything on the webpage.



any suggestions




CONFIG.INC



 $con=mysqli_connect("localhost","root@localhost","","test");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}



LOGINPROC PAGE




// Inialize session
session_start();

// Include database connection settings
include('config.inc');


// Retrieve username and password from database according to user's input
$login = mysql_query("SELECT * FROM users WHERE (username = '" . mysql_real_escape_string($_POST['username']) . "') and (password = '" . mysql_real_escape_string(md5($_POST['password'])) . "')");

// Check username and password match
if (mysql_num_rows($login) == 1) {
// Set username session variable
$_SESSION['username'] = $_POST['username'];
// Jump to secured page
header('Location: securedpage.php');
}

else {
// Jump to login page
header('Location: index.php');
}

?>


securedpage.php





// Inialize session
session_start();

// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['username'])) {
header('Location: index.php');
}


?>



Secured Page




This is secured page with session:


You can put your restricted information here.


Logout






No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...