Jump to content

PHP forum problems


DeanWhitehouse

Recommended Posts

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
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.