Jump to content

Recommended Posts

i am getting these errors when i try and login

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'crazyemochild'@'82.197.131.40' (using password: NO) in /home/www/mysitename.co.uk/nav_bar.php on line 86

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/www/mysitename.co.uk/nav_bar.php on line 86

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'crazyemochild'@'82.197.131.40' (using password: NO) in /home/www/mysitename.co.uk/nav_bar.php on line 87

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/www/mysitename.co.uk/nav_bar.php on line 87

but i only get these errors when i try to login on certain pages???

i can login on the home page, but only that page.

this is my code

<div class="login">
<?php
$server = str_replace("?logout","",$_SERVER['PHP_SELF']);
?>
<table class="log_in"><form action="<?php echo "$server"; ?>" method="post">
<th>Welcome</th>
<tr><td align="center">Username:</td></tr><tr><td align="center"><input type="text" name="user_name"  size="16" value="<?php echo $_COOKIE['uname']; ?>" /><br /></td></tr>
<tr><td align="center">Password:</td></tr><tr><td align="center"> <input type="password" name="user_password"  size="16" value="<?php echo $_COOKIE['userpw'] ?>" /><br /></td></tr>
<tr><td align="center"><input type="hidden" name="login" value="true"><input type="submit" value="Submit"></td></tr>
<tr><td align="centre"><input type="checkbox" name="remember" <?php echo $_COOKIE['check'] ?>> Remember Me </td></tr><tr><td align="center"><a href="register.php">[Register]</a></td></tr><tr><td align="center"><a href="forgot_password.php">[Forgot Password?]</a></td></tr></table>
</form>
</div>
<?php 
if ($_SESSION['is_valid'] == false) {
    if (isset($_POST['login'])) { 

        $user_name = mysql_real_escape_string($_POST["user_name"]);
        $user_password = mysql_real_escape_string($_POST["user_password"]);
        $cookiename = forumcookie;
        $verify_username = strlen($user_name);
        $verify_pass = strlen($user_password);
        if ($verify_pass > 0 && $verify_username > 0) {
            $userPswd = md5($user_password);
            $userpwsd = sha1($userPswd);
            $sql = "SELECT * FROM $user WHERE user_name='$user_name' AND user_password='$userpwsd' LIMIT 1;";
            $result = mysql_query($sql) or die(mysql_error() . " in $sql");
            if (mysql_num_rows($result) == 1) {
                $row = mysql_fetch_assoc($result);
                $s_userpass = serialize($userpass);
                $_SESSION['id_username'] = $row['user_name'];
                $_SESSION['id_user_password'] = $row['user_password'];
                $_SESSION['user_level'] = $row['userlevel'];
                $_SESSION['user_id'] = $row['user_id'];
                $_SESSION['is_valid'] = true;
                if (isset($_POST['remember'])) {
                  $checked = "checked='checked'";
		         setcookie("uname", $_SESSION['id_username'], time() + 86400*100);
                  setcookie("userpw", $user_password, time() + 86400*100);
			  setcookie("check",$checked, time() + 86400*100);
			  mysql_close();
             }
              header("Location:http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]);
            } else {
                echo "Login failed. Username or Password are not correct.";
            }
        } else {
            ?>
		<p><font style="font-size:small;">You left required field(s) blank</font></p>
		<?php
        }
    }
}
}
?>
</div>
</div>

 

and this is the home page

<?php
require_once 'includes/header.php';
require_once 'includes/db_connect.php';
?><div class="bg"></div>
<div class="clock"><?php echo gmdate('l, jS F Y');?> <span id="txt"></span></div> <?php
$filename = "install/instll.php";
if (file_exists($filename)) {
     ?><p class="exists"><br>Please remove the install.php file<br> and the install folder</p><?php
} else
{
?><p class="welcome"><?php echo"$welcome"; ?></p>
<?php
}
require_once 'nav_bar.php';
require_once 'includes/footer.php';
?>

 

and this is the member page(this is where i got the error)

<?php
require_once 'includes/header.php';
require_once 'includes/db_connect.php';
?><div class="bg"></div>
<div class="clock"><?php echo gmdate('l, jS F Y');?> <span id="txt"></span></div> 
<div class="member">
<?php
if ($_SESSION['is_valid'] == true){

if (isset($_GET['id'])) {
if ((int) $_GET['id'] > 0) {
require_once 'nav_bar.php';

$userid = $_GET['id'];
$sql = "SELECT * FROM $user WHERE `user_id`='{$userid}' LIMIT 0,1;";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$userprofname = $row['user_name'];
$profemail = $row['user_email'];
echo "$userprofname";
$show_email = $row['show_email'];
if (mysql_num_rows($result) < 1) {
     echo 'This ID does not exist in the database<br>';
 echo "<a href=\"members.php\">Return to Members Page</a>";
 exit();
}
if ($show_email == 1)
{ 
$email = "$profemail";
$email = explode('@',$email);
echo '<br>Email:'
?>
<a target="_blank" rel="external" href='javascript:window.location="mai"+"lto:"+"<?php echo $email[0]; ?>"+"@"+"<?php echo $email[1]; ?>";self.close();'onmouseover='window.status="mai"+"lto:"+"<?php echo $email[0]; ?>"+"@"+"<?php echo $email[1]; ?>"; return true;' onmouseout='window.status="";return true;'> Email Me</a>
<?php
}
elseif ($show_email == 0)
{
echo "<br>Email:   Hidden";
}
exit();
}
else {
echo "Unknown User ID! <br />";
echo "<a href=\"members.php\">Return to Members Page</a>";
exit();
}
}
//No ID passed to page, display user list:
$query = "SELECT user_id, user_name FROM $user";
$result = mysql_query($query) or die("Error:" . mysql_error());

if (mysql_num_rows($result) > 0) {
echo "User List:<br />";
while ($row = mysql_fetch_assoc($result)) {
  echo '<a href="?id=' . $row['user_id'] . '">' . $row['user_name'] . '</a><br />';
}
}
}
else
{
echo "Please login to view this page.";
}
?>
</div>
<?php
mysql_close();
require_once 'nav_bar.php';
require_once 'includes/footer.php';
?>

 

the nav_bar is where the login form is

any other questions , please ask me

Link to comment
https://forums.phpfreaks.com/topic/104129-solved-my_sql_real_escape/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.