Forum Moderators: coopster
This page should display the completed contents of a form and return a confirmation number. The problem is that eliboatc is not the correct user and not the user that I have entered in the db_login.php file. Not sure what is going on here, since it should be gathering the database login info from the db_login file.
[edited by: coopster at 2:09 pm (utc) on May 12, 2009]
[edit reason] no personal urls please TOS [webmasterworld.com] [/edit]
<?php
$db_host = 'localhost';
$db_database = 'eliboatc_vanman';
$db_username = '#*$!x';
$db_password = '#*$!x';
//*******************************************************************************
function vanstand_connect($dbhost, $dbdatabase, $dbusername, $dbpassword)
{
$connection = mysql_connect($dbhost, $dbusername, $dbpassword);
if (!$connection)
{
die ("Cannot connect to database: <br />".mysql());
}
//choosing database
$db_select = mysql_select_db($dbdatabase);
if(!$db_select)
{
die("Cannot select the database: <br \>".mysql_error());
}
}
//******************************************************************************
function restricted($logout)
{
require_once('db_login.php');
if($logout=='logout'){
echo "logout code here";
session_start();
session_unregister();
session_unset();
session_destroy();
echo "session is".session_is_registered();
}else{
session_start();
if (empty($_SESSION['user_id']))
{
if (!isset($_SERVER['PHP_AUTH_USER']) ¦¦ !isset($_SERVER['PHP_AUTH_PW']))
{
header('WWW-Authenticate: Basic realm="Member Area"');
header("HTTP/1.0 401 Unauthorized");
echo "You must enter a username and password.";
exit;
}
//connect to db
vanstand_connect('localhost', 'Vanstand', 'root', '');
$web_username = mysql_real_escape_string($_SERVER['PHP_AUTH_USER']);
$web_password = mysql_real_escape_string($_SERVER['PHP_AUTH_PW']);
$query = "SELECT user_id, username";
$query.= " FROM users WHERE ";
$query.= "username='".$web_username."' AND password='".$web_password."' LIMIT 1";
$result = mysql_query($query);
if(!$result)
{
die("Cannot query: <br />".mysql_error());
}
if (!$result_row = mysql_fetch_array($result, MYSQL_ASSOC))
{
header('WWW-Authenticate: Basic realm="Member Area"');
header("HTTP/1.0 401 Unauthorized");
echo "Your username and password combination was incorrect.";
exit;
}
$_SESSION['user_id'] = $result_row['user_id'];
$_SESSION['username'] = $result_row['username'];
}
if (empty($_SESSION['user_id']))
{
echo "empty";
}
$value = $_SESSION['username'];
//setcookie("MoverCookie",$value);
echo "Welcome <b>".$_SESSION['username'].'</b>.';
mysql_close($connection);
}
}
//**************************************************************************************
function new_info($query)
{
require_once('db_login.php');
// connect to db.
vanstand_connect('localhost', 'Vanstand', 'root', '');
$result = mysql_query($query);
if (!$result)
{
die("Cannot Insert: <br />".mysql_error());
}
;
}
//***************************************************************************************
?>
$db_host = 'localhost';
$db_database = 'eliboatc_vanman';
$db_username = '#*$!x';
$db_password = '#*$!x';
//*******************************************************************************
function vanstand_connect($dbhost, $dbdatabase, $dbusername, $dbpassword)
{
$connection = mysql_connect($dbhost, $dbusername, $dbpassword);
Your variables and have an underscore: db_host, etc, while the underscore is missing in the function. This could be one of the reasons for not connecting to the db.
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'eliboatc'@'localhost' (using password: NO) in /home3/eliboatc/public_html/#*$!XX/thankyou.php on line 96
eliboatc is not a user of the database, so I don't understand why it is trying to use that user when a different user is specified in the db_login.php file.
$db_host = 'localhost';
$db_database = 'eliboatc_vanman';
$db_username = '#*$!x';
$db_password = '#*$!x';
You are not using them in your connection function:
function vanstand_connect($dbhost, $dbdatabase, $dbusername, $dbpassword) { vanstand_connect('localhost', 'Vanstand', 'root', '');