Kyza Posted November 18, 2010 Share Posted November 18, 2010 Hey Im getting this error:Warning: mysql_query() [function.mysql-query]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/brad/public_html/index.php on line 66Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/brad/public_html/index.php on line 66Access denied for user 'nobody'@'localhost' (using password: NO)It seems its in the index.php file, here is the code, im not sure what to change, please help:<?phpob_start();session_start();include "./global.php";$action = $_GET['act'];$actions_array = array('forum','create','topic','reply','mod');?><html> <head> <title>Forum</title> <link rel="stylesheet" type="text/css" href="./style.css"> <script language="Javascript"> function confirmLogout(){ var agree = confirm("Are you sure you wish to logout?"); if(agree){ return true ; }else { return false ; } } </script> </head> <body> <center> <div id="holder"> <div id="userInfo"> <?php if($_SESSION['uid']){ $sql = "SELECT * FROM `users` WHERE `id`='".$_SESSION['uid']."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ session_destroy(); echo "Please <a href=\"./login.php\">Login</a> to your account, or <a href=\"./register.php\">Register</a> a new account!\n"; }else { $row = mysql_fetch_assoc($res); echo "Welcome back, <a href=\"./index.php?act=profile&id=".$row['id']."\">".$row['username']."</a>! <a href=\"./logout.php\" onClick=\"return confirmLogout()\">Logout</a>\n"; echo "<br>\n"; echo "<a href=\"./index.php\">Forum Index</a>\n"; if($row['admin'] == '1'){ echo " | <a href=\"./admin.php\">Administrative Section</a>\n"; } } }else { echo "Please <a href=\"./login.php\">Login</a> to your account, or <a href=\"./register.php\">Register</a> a new account!\n"; } $admin_user_level = $row['admin']; ?> </div> <div id="content"> <?php if(!$action || !in_array($action,$actions_array)){ $sql1 = "SELECT * FROM `forum_cats` WHERE `admin` < ".$row['admin']."+1"; $res1 = mysql_query($sql1) or die(mysql_error()); $i=1; while($row2 = mysql_fetch_assoc($res1)){ echo "<div id=\"fcontent\">\n"; echo " <div class=\"header\" id=\"header_".$i."\" onMouseOver=\"this.className='headerb'\" onMouseOut=\"this.className='header'\">".$row2['name']."</div>\n"; $sql2 = "SELECT * FROM `forum_sub_cats` WHERE `cid`='".$row2['id']."' AND `admin` < ".$row['admin']."+1"; $res2 = mysql_query($sql2) or die(mysql_error()); while($row3 = mysql_fetch_assoc($res2)){ echo " <div id=\"content\">\n"; echo " <a href=\"./index.php?act=forum&id=".$row3['id']."\">".$row3['name']."</a><br>\n"; echo " " . $row3['desc'] . "\n"; echo " </div>\n"; } echo "</div>\n"; $i++; } }else { if($action == 'forum'){ include "./includes/forum.php"; } if($action == 'create'){ if(!$_SESSION['uid']){ header("Location: login.php"); }else { include "./includes/create.php"; } } if($action == 'topic'){ include "./includes/topic.php"; } if($action == 'reply'){ if(!$_SESSION['uid']){ header("Location; login.php"); }else { include "./includes/reply.php"; } } if($action == 'mod'){ if(!$_SESSION['uid']){ header("Location; login.php"); }else { include "./includes/mod.php"; } } } ?> </div> </div> </center> </body></html><?phpob_end_flush();?> Link to comment Share on other sites More sharing options...
Synook Posted November 18, 2010 Share Posted November 18, 2010 You have to connect to your database first, using mysql_connect(), with valid database credentials. Or else it tries to connect anonymously (as "nobody"), but the connection is being rejected. Link to comment Share on other sites More sharing options...
bitdowner Posted November 18, 2010 Share Posted November 18, 2010 Hello , try like this <?php// we connect to example.com and port 3307$link = mysql_connect('example.com:3307', 'mysql_user', 'mysql_password');if (!$link) { die('Could not connect: ' . mysql_error());}echo 'Connected successfully';mysql_close($link);// we connect to localhost at port 3307$link = mysql_connect('127.0.0.1:3307', 'mysql_user', 'mysql_password');if (!$link) { die('Could not connect: ' . mysql_error());}echo 'Connected successfully';mysql_close($link);?> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.