I know there are many posts on this subject, however after reading them I am still not seeing what the problem is in my code.
I have run the SQL Query in phpmyadmin and it works fine, calling up the correct entry from the database.
The error is being raised in the function "process_login()" at the line that reads
$Result = mysql_query ($Query, $Connection) or die("Query failed : " . mysql_error($Connection));
Here is the code I pulled together from 3 different files (2 includes) to try and debug it all in one file.
<?php
// set_include_path("./inc");
// require_once "sqlFunctions.php";
// require_once "loginBox.php";
$hostname="localhost";
$database="testDataBase";
$username="phpuser";
$password="phpuser";
$Connection = false;
$UserData;
$LoginErrorMsg;
if($_POST[mode]=="LogIn"){process_login();}
if($_POST[mode]=="LogOut"){logout_user();}
function connectToDatabase(){
global $hostname, $username, $password, $database, $DeBug;
if($Connection){return (1);}
if($Connection=mysql_connect($hostname,$username,$password)){
mysql_select_db ($database, $Connection) or die('Database connection error: ' . mysql_error($Connection));
return (1);
}else{return (0);} // handle error elsewhere
};
function disconnect(){
global $Connection;
if($Connection != NULL){mysql_close($Connection);}
}
function process_login(){
global $UserData,$Connection,$LoginErrorMsg,$database,$DeBug;
if($Connection == NULL){$connectionStatus = connectToDatabase();}
// if(!$connectionStatus){myErrorHandeler("No server connection");}
$Query = "SELECT * FROM logins WHERE login = '$_POST[LoginName]' AND pwd = password('$_POST[LoginPassword]')";
$Result = mysql_query ($Query, $Connection) or die("Query failed : " . mysql_error($Connection));
if(mysql_num_rows($Result)){
$UserData = mysql_fetch_array($Result);
mysql_free_result($Result);
$_SESSION[Verified]=1;
$_SESSION[UserId]=$UserData{'id'};
$_SESSION[UserFname]=$UserData{'Fname'};
return 1;
}else{
mysql_free_result($Result);
$_SESSION[Verified]='';
$_SESSION[UserId]='';
$_SESSION[UserFname]='';
$LoginErrorMsg='<br>Login Name<br>and/or password<br>is invalid.';
return 0;
}
}
function print_login_box(){
global $UserData,$LoginErrorMsg;
?>
<form action="<?php echo $ConfigData{'scriptname'}?>" method="POST">
<?php if($_SESSION[UserId] == 0){ ?>
Name:<input type="text" size="16" maxlength="16" name="LoginName" value="<?php echo $_POST[LoginName] ?>"><br>
Password:<input type="password" size="16" maxlength="16" name="LoginPassword" value="<?php echo $_POST[loginPassword] ?>"><br>
<input type="submit" name="mode" value="LogIn"><br>
<font color="#D8D8D8"><?php echo $LoginErrorMsg; ?></font>
<input type="hidden" name="Currentpage" value="<?php echo $_SESSION[Currentpage] ?>">
<?php }else{ ?>
<input type="hidden" name="Currentpage" value="<?php echo $_SESSION[Currentpage] ?>">
<font color="#D8D8D8">Welcome back,<br>
<?php echo $_SESSION[UserFname];if($_SESSION[Verified]!=1){echo "*";} ?></font>
<input type="submit" name="mode" value="Log Out">
<?php } ?>
</form>
<?php } ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Welcome to <? print $host; ?></title>
<link rel="stylesheet" type="text/css" href="./inc/Vstyle.css" />
</head>
<body>
<div id="container">
<Table class="ex" width=100%>
<Tr>
<td colspan=2 width =85%><img src="./images/StandardBanner.jpg"></td>
<td align=right valign=top width=15% border=1><?php print_login_box();?></td>
</Tr>
<td width=15%>Blah blah blah</td>
<td width=70%>Lots of Blah blah blah</td>
<td width=15%>Blah blah blah</td>
</table>
</div>
</body>
</html>
<?php
disconnect();
?>