Forum Moderators: coopster
I am hoping someone can help. Code is as follows. (Btw i know its basic its just a proof of concept) Many Thanks
<?php require_once('../../../Connections/test.php');
$auth = false; // Assume user is not authenticated
$name =$_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];
if (isset( $name ) && isset($pass)) {
// the query
$query = "SELECT name, password FROM Admin WHERE
Name = '".$name."' AND
Password = '".$pass."'";
// Execute the query and put results in $result
$result = mysql_query( $query )
or die ( 'Unable to execute query.' );
// Get number of rows in $result.
$num = mysql_numrows( $result );
if ( $num != 0 ) {
// A matching row was found - the user is authenticated.
$auth = true;
}
}
if ( ! $auth ) {
header( 'WWW-Authenticate: Basic realm="Pharmacy Admin"' );
header( 'HTTP/1.0 401 Unauthorized' );
echo "Authorization Required";
} else {
session_register('authorised');
header("location:sucess.php?title=go");
}
?>
<!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>Login</title>
<link href="../../../css/1.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header3">
The details you entered are in correct <a href="../../../index.html">click here</a> to return to the home page</div>
</body>
</html>
$dbuser="user";
$dbpass="password";
$dbname="pharma"; //the name of the database
$connect = mysql_connect("localhost", $dbuser, $dbpass)
or die("Connection Failure to Database");
mysql_select_db($dbname, $connect) or die ($dbname . " Database not found. " . $dbuser);
$auth = false; // Assume user is not authenticated
$name =$_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];
if ($name !="" && $pass!= "") {
// the query
$query = "SELECT name, password FROM Admin WHERE
Name = '$name' AND
Password = '$pass'";
// Execute the query and put results in $result
$result = mysql_query( $query )
or die ( 'Unable to execute query.' );
// Get number of rows in $result.
$num = mysql_numrows( $result );
if ( $num != 0 ) {
// A matching row was found - the user is authenticated.
$auth = true;
}
}
if ( ! $auth ) {
header( 'WWW-Authenticate: Basic realm="Pharmacy Admin"' );
header( 'HTTP/1.0 401 Unauthorized' );
} else {
session_register('authorised');
header("location:sucess.php?title=go");
}
?>
<!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>Login</title>
<link href="../../../../css/1.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {font-size: 16}
-->
</style>
</head>
<body>
<div id="header3">
<div align="center">
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p><h2><?php echo "Authorization Required"; ?></h2></p>
<p> </p>
<p class="style1">The details you entered are incorrect <a href="../../../../index.php">click here</a> to return to the home page</p>
</div>
</div>
</body>
</html>
when I change the values to reflect the remote server, i get the "failed to execute query" message.
There is nothing wrong with the db, i can use it to make tables slightly different way on other pages that use an include connection.php which work fine in test and live.
Once again many thanks in advance
Jon