I have been using the PHP HACKS book to try to build a login script for a website I am building but I seem to be doing something wrong, when I enter the login and password information on the index page then click login I get a blank page. I am not sure I installed the pear module correctly or have it declared in my script? Please help
here is the code for the index.php, which I do not think has any errors
<html>
<head><title>Login</title></head>
<body>
<?php
if ( $_GET['bad'] == 1 ) { ?>
<font color="red">Bad login or password, please try again<br/></font>
<?php } ?>
<form action="http://www.onedispatch.com/test/login.php" method="post">
<table width="300" border="0" cellspacing="0" cellpadding="2">
<tr><td>User name:</td><td><input type="text" name="user" /></td></tr>
<tr><td>Password:</td><td><input type="password" name="password" /></td></tr>
<tr><td colspan="2"><center><input type="submit" value="login" /></center></td></tr>
</table>
</form>
</body>
</html>
Here is the code for the script handler where I need the help:
<?php
require_once( "http://www.onedispatch.com/mylibs/DB-1.7.6/DB.php" );
$dsn = 'mysql://username:password@http://myhost';
$db =& jarodd_testDB::Connect( $dsn, array() );
if (PEAR::isError($db)) {die($db->getMessage()); }
$res = $db->query( "SELECT id FROM users WHERE name=? AND password=MD5(?)",
array( $_POST['user'], $_POST['password'] ) );
$row = array( null );
if ( $res != null )
$res->fetchInto( $row );
if ( $row[0] != null )
{
session_start();
$_SESSION['user'] = $row[0];
header( "Location: http://www.onedispatch.com/test/welcome.php" );
}
else
{
header( "Location: http://www.onedispatch.com/test/index.php?bad=1" );
}
?>
Thanks in advance!