DeanWhitehouse Posted May 5, 2008 Share Posted May 5, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/104129-solved-my_sql_real_escape/ Share on other sites More sharing options...
trq Posted May 5, 2008 Share Posted May 5, 2008 It would appear your database connection is failing. Make sure you have the correct username, password and host. Quote Link to comment https://forums.phpfreaks.com/topic/104129-solved-my_sql_real_escape/#findComment-533118 Share on other sites More sharing options...
DeanWhitehouse Posted May 5, 2008 Author Share Posted May 5, 2008 as i said, i can login on the home page, just not any of my other pages. so the connection is fine. Quote Link to comment https://forums.phpfreaks.com/topic/104129-solved-my_sql_real_escape/#findComment-533120 Share on other sites More sharing options...
DeanWhitehouse Posted May 5, 2008 Author Share Posted May 5, 2008 i solved it , i had the mysql_close(); before the include for the nav_bar, therefore closing the connection the second i made it Quote Link to comment https://forums.phpfreaks.com/topic/104129-solved-my_sql_real_escape/#findComment-533122 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.