I'm having MySQL errors on my website.
For the login system and the message posting system.
The error is:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'brezerd1_BIDA1'@'localhost' (using password: YES) in /home/brezerd1/public_html/login/checklogin.php on line 13 cannot connect
My database server is localhost and the username and password is correct. The login system goes like this:
index.php in login.brezerd.net acts as the input form.
Then, checklogin.php validates the inputs.
If it succeeds, login_success is displayed.
To keep them logged in, I've implemented code on every page (in my template.php) to access the data and if it can't then show "Login?" and if it can then display user info (like Welcome, [username]).
The code is as follows:
The code for the login system (form) is:
<?php
include("/home/brezerd1/public_html/template.php");
ini_set('session.cookie_domain',
substr($_SERVER['SERVER_NAME'],strpos($_SERVER['SERVER_NAME'],"."),100));
?>
<!--7:55:00PM 17/12/2010 AEST---!>
<body>
<script type="text/javascript" defer="defer">
window.alert("BIDAS (Brezerd.net IDentification Account System) is currently indev (like a lot of Brezerd.net). However, unlike a lot of the site, it's unstable.");
</script>
<!-->
<h2>
BREZERD.NET LOGIN (INDEV)
</h2>
<table width="300" border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="password" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</head>
<?php
include("/home/brezerd1/public_html/footer.php");
?>
<html>
The code for the checklogin file:
<?php
ini_set('session.cookie_domain',
substr($_SERVER['SERVER_NAME'],strpos($_SERVER['SERVER_NAME'],"."),100));
ob_start();
$host="localhost"; // Host name
$username="brezerd1_BIDA1"; // Mysql username
$password="3.14159265358979323846"; // Mysql password
$db_name="brezerd1_users"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
header("location:index.php");
echo "Error";
}
ob_end_flush();
?>
The code for login_success:
<?
ini_set('session.cookie_domain',
substr($_SERVER['SERVER_NAME'],strpos($_SERVER['SERVER_NAME'],"."),100));
session_start();
$username = $_SESSION['myusername'];
echo "<b>"."Welcome ". $username."</b>";
if(!session_is_registered(myusername)){
header("location:index.php");
}
?>
<html>
<body>
<br>
Login Successful!
<a HREF="/Logout.php">Logout</a>
</body>
</html>
And the code implemented on every page:
<?php
ini_set('session.cookie_domain',substr($_SERVER['http://brezerd.net'],strpos($_SERVER['http://brezerd.net'],"."),100));
session_start();
print $_SESSION['BIDAN'];
if($_SESSION['BIDAN']!= null)
{
//echo ("Logged In as ".$_SESSION['username']);
}
if ($_SESSION['BIDAN']= null)
{
echo ("Login?");
}
//-END OF BIDAS CODE-
?>
My apologies if this is overly long and boring but I would like an answer.
Thank you very much.
Edited by Hunter100, 16 April 2011 - 05:20 PM.
Poor grammar.


Sign In
Create Account


Back to top









