DeanWhitehouse Posted April 21, 2008 Share Posted April 21, 2008 I have written a forum, and i get an error message, but this only displays when i am not logged in. Warning: mysql_query() [function.mysql-query]: Access denied for user 'crazyemochild'@'82.197.131.40' (using password: NO) in /home/www/deanwhitehouse.awardspace.co.uk/test/main_forum.php on line 9 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/www/deanwhitehouse.awardspace.co.uk/test/main_forum.php on line 9 Access denied for user 'crazyemochild'@'82.197.131.40' (using password: NO) this is the main_forum.php code <?php require_once 'db_connect.php'; require_once 'config_table.inc.php'; require_once 'header.php'; require_once 'nav_bar.php'; require_once 'logged_in.php'; $sql="SELECT * FROM $forum_quest ORDER BY id DESC"; $result=mysql_query($sql) or die (mysql_error()); ?> <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td> <td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td> <td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td> <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td> <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ // Start looping table row ?> <tr> <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td> <td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['view']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['reply']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td> </tr> <?php // Exit looping and close connection } mysql_close(); ?> <tr> <td colspan="5" align="right" bgcolor="#E6E6E6"><a href="create_topic.php"><strong>Create New Topic</strong> </a></td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/102222-php-forum-problems/ Share on other sites More sharing options...
dptr1988 Posted April 21, 2008 Share Posted April 21, 2008 It sounds you havn't setup the proper config variables for the database connection. In the file 'db_connect.php', double check that you are actually getting the proper host/username/password/database varialbles. Quote Link to comment https://forums.phpfreaks.com/topic/102222-php-forum-problems/#findComment-523310 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 Yep, something's wrong with your database connection. Check it. =) Quote Link to comment https://forums.phpfreaks.com/topic/102222-php-forum-problems/#findComment-523313 Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2008 Author Share Posted April 21, 2008 the thing is though, that it works perfectly when i am logged in, no errors at all, but when i am logged out,i get lots of errors Quote Link to comment https://forums.phpfreaks.com/topic/102222-php-forum-problems/#findComment-523318 Share on other sites More sharing options...
dptr1988 Posted April 21, 2008 Share Posted April 21, 2008 Yes, when you are logged out, the script may not be includeing the neccessary db config files. Please double check the contents of those config vars. You can do that by 'echo'ing the right before using them in the mysql_connect function and then going to your forum and then logging out and showing us the 'echo'ed results. Quote Link to comment https://forums.phpfreaks.com/topic/102222-php-forum-problems/#findComment-523321 Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2008 Author Share Posted April 21, 2008 ok, now when i add the db_connect script to the actual page, instead of using require_once 'db_connect'; i added require_once 'config.inc.php'; // Connect to database mysql_connect($dbhost,$dbuser,$dbpass) or die('Could not connect: ' . mysql_error()); // Select database mysql_select_db($dbname) or die('Could not find the database: ' . mysql_error()); $sql="SELECT * FROM $forum_quest ORDER BY id DESC"; $result=mysql_query($sql) or die (mysql_error()); which is the db_connect form, and this works Quote Link to comment https://forums.phpfreaks.com/topic/102222-php-forum-problems/#findComment-523323 Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2008 Author Share Posted April 21, 2008 ok, i added this code if(mysql_connect) { echo "You have successfully connected with these details to '$dbname'. <br>Username - '$dbuser'<br> Password - '$dbpass'<br> Database Host - '$dbhost'<br>";} just under the require_once 'db_connect.php'; and i get these errors You have successfully connected with these details to '********'. Username - '********' Password - '*******' Database Host - '********' //stars are not shown to me\\ Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/www/deanwhitehouse.awardspace.co.uk/test/main_forum.php:5) in /home/www/deanwhitehouse.awardspace.co.uk/test/header.php on line 3 Warning: mysql_query() [function.mysql-query]: Access denied for user 'crazyemochild'@'82.197.131.40' (using password: NO) in /home/www/deanwhitehouse.awardspace.co.uk/test/main_forum.php on line 12 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/www/deanwhitehouse.awardspace.co.uk/test/main_forum.php on line 12 Access denied for user 'crazyemochild'@'82.197.131.40' (using password: NO) Quote Link to comment https://forums.phpfreaks.com/topic/102222-php-forum-problems/#findComment-523338 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 You can't start a session after headers have been sent. Start the session before the output from echos. Quote Link to comment https://forums.phpfreaks.com/topic/102222-php-forum-problems/#findComment-523343 Share on other sites More sharing options...
dptr1988 Posted April 21, 2008 Share Posted April 21, 2008 That is strange! How come it's say "usering password: NO" when you are using the password? @DarkWater: Sessions don't have anything to do this. The only reason for the session errors, is becuase he was printing out a debug string that I requested. Quote Link to comment https://forums.phpfreaks.com/topic/102222-php-forum-problems/#findComment-523350 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 Don't do if (mysql_connect), do this: $connection = mysql_connect(user, details, here); if (is_resource($connection)) { echo "You have successfully connected with these details to '$dbname'. <br>Username - '$dbuser'<br> Password - '$dbpass'<br> Database Host - '$dbhost'<br>";} } else { die ("Connection failed."); } Try that and tell us the output. Quote Link to comment https://forums.phpfreaks.com/topic/102222-php-forum-problems/#findComment-523355 Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2008 Author Share Posted April 21, 2008 so what do i need to change , i have tried placing the require_once for the file with the session_start(); at the thop of the list of requires and that didn't work. also this Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/www/deanwhitehouse.awardspace.co.uk/test/main_forum.php:5) in /home/www/deanwhitehouse.awardspace.co.uk/test/header.php on line 3 line 5 in main_forum.php is the echo if(mysql_connect) { echo "You have successfully connected with these details to '$dbname'. <br>Username - '$dbuser'<br> Password - '$dbpass'<br> Database Host - '$dbhost'<br>";} to fix the headers sent problem i moved the require for the header.php to the top and that worked, but i still can't connect to it without being logged, in , its really wierd Quote Link to comment https://forums.phpfreaks.com/topic/102222-php-forum-problems/#findComment-523364 Share on other sites More sharing options...
dptr1988 Posted April 21, 2008 Share Posted April 21, 2008 You can't just use 'mysql_connect()' by it's self. You need to use 'mysql_connect($dbhost, $dbuser, $dbpass)' and save the result of that function and then analize the result. Also when debugging, you should uncontionally print the values that are in question, and print a 'yes'/'no' if you are wanting to determine the result of a if statment. Quote Link to comment https://forums.phpfreaks.com/topic/102222-php-forum-problems/#findComment-523369 Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2008 Author Share Posted April 21, 2008 the connection is already being made in db_connect.php as i said it does work fine when im logged in, but not when i'm not Quote Link to comment https://forums.phpfreaks.com/topic/102222-php-forum-problems/#findComment-523374 Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2008 Author Share Posted April 21, 2008 FOUND THE PROBLEM <?php if ($_SESSION['is_valid'] == true){ if ($_SESSION['user_level'] == 2){ echo "<table class='logged_in'><tr><td> Welcome"; echo $_SESSION['username']; echo ",<br><a href=''>User Profile</a><br> <a href=''>Settings</a><br> <a href='logout.php'>Logout</a> </td></tr><tr><td><font color='white'>Logged In</font></td></tr></table>"; } if ($_SESSION['user_level'] == 1){ echo "<table class='logged_in'><tr><td> Welcome "; echo $_SESSION['username']; echo ",<br><a href='user_profile.php'>User Profile</a><br> <a href='user_setting.php'>Settings</a><br> <a href='admin_centre.php'>Admin Area</a><br> <a href='logout.php'>Logout</a> </td></tr><tr><td><font color='white'>Logged In</font></td></tr></table>"; } } else { include_once ('login.php'); } ?> the include at the bottom, if i change this to an echo it works. any ideas why? Quote Link to comment https://forums.phpfreaks.com/topic/102222-php-forum-problems/#findComment-523382 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.