Hi all,
I'm having trouble with mysql.
I've just finished my php coding for HTTP authentication and with some help am now getting a login window pop up whenever I click on a link on my website that directs to Auth.php.
The code for this is below:
<?php
/* Program: Auth.php
* Desc: Program that prompts for a user name and
* password from the user using HTTP authentication.
* The program then tests whether the user
* name and password match a user name and password
* pair stored in a MySQL database.
*/
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="family pics"');
header('HTTP/1.0 401 Unauthorized');
echo 'This webpage requires athentication!';
exit;
}
else{
include("Vars.inc");
$user_name = trim($_SERVER[‘PHP_AUTH_USER’]);
$user_password = trim($_SERVER[‘PHP_AUTH_PW’]);
$connection = mysql_connect($host,$user,$password)or die;
echo 'Couldn’t connect to server.';
$db = mysql_select_db($database,$connection)or die;
echo 'Couldn’t select database.';
$sql = "SELECT user_name FROM valid_user WHERE user_name = ‘$user_name' AND password = md5(‘$user_password’)";
$result = mysql_query($sql)or die;
echo 'Couldn’t execute query.';
$num = mysql_num_rows($result);
if ($num < 1)
{
echo 'The User Name or Password you entered is not valid.';
exit;
}
}
include("familypics.inc");
?>
My problem is I now cannot get the mysql query portion of my coding to work. When I enter the username and password in the login window that pops up, I get the error "Parse error: syntax error, unexpected T_STRING in /home/allummfa/public_html/Vars.inc on line 8".
I'm actually learning php from a book but i dont have much material to learn mysql. The database is created by my web hosting company called UserAccount. The scripts I have used to create the database table and store information needed by the php mysql functions are stored in a file called Vars.inc. This file is located in my html public folder, alongside my html and php files. The contents of Vars.inc are below:
<?php
$host = "localhost";
$user = "myusername";
$password = "mypassword";
$database = "UserAccount";
CREATE TABLE valid_user (user_name CHAR(25) NOT NULL, password CHAR(25) NOT NULL, create_date DATE NOT NULL, PRIMARY KEY(user_name));
?>
I've been researching in google and tried a few changes with no joy.
Can anyone see whats wrong in the Vars.inc file? Should I really use the .inc extension?
I have entered an "include" command in my Auth.php file pointing towards Vars.inc. I assume that is ok.
Help!