Forum Moderators: coopster
Parse error: syntax error, unexpected T_STRING in /home/bpapergu/public_html/loginprocessor.php on line 19
//Here is the processor page:
//The error starts with $query which is line 19
<?php
//Database Information
$dbhost = "localhost";
$dbname = "fake";
$dbuser = "fake";
$dbpass = "fake";
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
session_start();
$username = $_POST['username'];
$pword = md5($_POST['pword']);
//line 19 is below
$query = "SELECT * FROM " userinfo "WHERE " username='$username' and pword='$pword';
$result = mysql_query($query);
if (mysql_num_rows($result)!= 1) {
$error = "Bad Login";
include 'loginpage.php';
} else {
$_SESSION['username'] = '$username';
include 'home.php';
}
?>
$query = "SELECT * FROM userinfo WHERE username='$username' and pword='$pword'";
$result = mysql_query($query);
if (mysql_num_rows($result)!= 1) {
$error = "Bad Login";
include 'loginpage.php';
} else {
$_SESSION['username'] = '$username';
include 'index.html';
}
$query = "SELECT * FROM userinfo WHERE username='$username' and pword='$pword'";
$result = mysql_query($query);
echo "How many results: ".mysql_num_rows($result);
die();
if (mysql_num_rows($result)!= 1) {
$error = "Bad Login";
include 'loginpage.php';
} else {
$_SESSION['username'] = '$username';
include 'index.html';
}
That will at least tell you if the number is what you expect. I'm guessing it will be 0.
JAG
<?php
//Database Information
$dbhost = "localhost";
$dbname = "name";
$dbuser = "user";
$dbpass = "password";
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
session_start();
$username = $_POST['username'];
$pword = md5($_POST['pword']);
$query = "SELECT * FROM userinfo WHERE username='$username' and pword='$pword'";
$result = mysql_query($query);
echo "How man results: ".mysql_num_rows($result);
die();
if (mysql_num_rows($result)!= 1) {
$error = "Bad Login";
include 'loginpage.php';
} else {
$_SESSION['username'] = '$username';
include 'index.html';
}
?>
If it was non-zero (hopefully 1) then something is likely wrong with the index.html page. You might try redirecting to it with:
header("Location: index.html\n\n");
exit();
instead of including it. Comment or remove the echo and die lines.
What JAG was saying earlier is that you should do this:
$username = mysql_real_escape_string($_POST['username']);
$pword = md5(mysql_real_escape_string($_POST['pword']));
to safeguard against sql injection.