Forum Moderators: coopster
PHP LOGIN CODE
I tried that mod, but still getting a blank page. Here's my updated code - any ideas? I've posted my form as well so you can see how I'm passing the variables. Any ideas? Thanks for your help so far:
login.php
...
<form name="authenticate" method="post" action="authenticate.php">
<input name="username" type="text" value="username" size="20"/><br>
<input name="password" type="text" value="password" size="20"/><br><br>
<input type="submit" name="submit" value="submit"/>
<input type="reset" name="reset" value="reset"/>
</form>
...
authenticate.php
<?php
require_once('dbconnect.php');
// Select the Database
if (!@mysql_select_db('wedding')) {
exit('<p>Can\'t select the WEDDING database</p>');
}
// Start session
session_start();
$_SESSION['logged'] = 0;
// Check against database if form submitted
if (isset($_POST['submit'])) {
$username = $_POST['username'];
$sql = "SELECT * FROM people WHERE username='$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'); // Content would follow on here
}
else {
exit('Login Failed. Please try putting in your details again');
mr_nabo, if it still isn't working your should do a few things to get some errors.
1) Check your error logs on your server. Most likely the same error log for your server itself.
2) Add some error handling to your code:
<?php
session_start();
#
require_once('dbconnect.php');
#
if (!mysql_select_db('wedding')) {
exit('<p>Can\'t select the WEDDING database</p>');
}
#
$_SESSION['logged'] = 0;
#
if (isset($_POST['submit'])) {
#
$username = mysql_real_escape_string($_POST['username']);
$sql = "SELECT * FROM people WHERE username='$username'";
$sql = mysql_query($sql) or die(mysql_error());
$result = mysql_fetch_assoc($sql);
#
if(($_POST['username'] == $result['username']) &&
($_POST['password'] == $result['password'])) {
$_SESSION['user'] = $result['id'];
$_SESSION['logged'] = 1;
#
echo 'Login success'; // Content would follow on here
#
} else {
#
exit('Login Failed. Please try putting in your details again');
#
}
}
[edited by: eelixduppy at 10:47 am (utc) on April 3, 2007]
[edit reason] no URLs, please [/edit]
so when you try to login it just gives you a blank page?
have you checked your error logs?
Can you find a specific error anywhere?
have you tried turning on display_errors [php.net]?
have you tried turning up error_reporting [php.net]?