Jump to content

Can't get username/password mysql-based retrieval working


mr_nabo

Recommended Posts

Hi,

 

Hope you can help me with my code. I can't seem to figure out how to set up a MySQL-based password and username php app. Here's my code, it just goes blank when I run it and I can't figure out why. Anyone help?

 

Thanks

 

<?php require_once('header.inc'); ?>

<?php

require_once('dbconnect.php');

// Select the Database

if (!@mysql_select_db('wedding')) {
exit('<p>Can\'t select the WEDDING database</p>');

}

session_start();

$_SESSION['logged'] = 0;

if (isset($_POST['submit'])) {

$sql = "SELECT * FROM people WHERE username='$_POST['username']'"; //make sure tablename and username match your form and database
$sql = mysql_query($sql);
$result = mysql_fetch_assoc($sql);

if($_POST['username'] == $result['username'] &&
$_POST['password'] == $result['password']) {
$_SESSION['user'] = $result['id'];
$_SESSION['logged'] = 1;

exit('Login success');

}

else {

exit('Login Failed. Please try putting in your details again');

}

?>

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.