Jump to content

Catchable fatal error in code.


dean7

Recommended Posts

Hi all, Im trying to code a blacklist for my website but ive came accross a error which says:

 

Catchable fatal error: Object of class stdClass could not be converted to string in /home/www/*********.com/cashbl.php on line 33

 

This is my code:

 

<?php
// Check errors thing:
ini_set ('display_errors', 1);
error_reporting (E_ALL);
// End check errors thing.
?>
<?php
session_start();
// Start inculdes files:
include ("includes/config.php");
include ("includes/functions.php");
// End includes files.

// Login thing:
if(!isset($_SESSION['username']) || !isset($_SESSION['password'])){
header("Location: index.php");
}else{
$fetch_users_data = mysql_fetch_object(mysql_query("SELECT * FROM `users` WHERE username='".$_SESSION['username']."'"));
}
// end login thing.

$username = $_SESSION['username'];
$getmoney = mysql_query("SELECT username FROM users ORDER BY money DESC");
$grr = mysql_fetch_object($getmoney);
$account = mysql_query("SELECT money FROM users ORDER BY money DESC");
$ammount = mysql_fetch_object($account);
echo "<ul>";
$i = 0;
do {
$i++;
echo  "<table width='50%' class='table' cellpadding='0' cellspacing='0'><tr><td class='header' colspan='4'><center>Money Blacklist</center></td></tr>
<tr><td colspan='1' class='forum'>Place:</td><td colspan='1' class='forum'>Username:</td><td colpan='1' class='forum'>Money:</td></tr>
<tr><td>{$i}</td><td><a href='profile.php/view_user={$grr}'>{$grr}</td><td>£{$fetch_users_data->money}</td></tr></table>"; // Line 33
} while($i < 10);
echo "</ul>";
?>
<link href="regstyle.css" rel="stylesheet" type="text/css">
<body class="body">
</body>

 

Anyone know why its displaying that errror?

 

Thanks in advance .

Link to comment
Share on other sites

You are outputting $fetch_users_data->money, which is the money of the account you are on. I suspect you wanted to use $ammount->money You seem to be just throwing down some code without even looking at it to see if it is doing what you want.

 

You are also executing two similar queries to get two pieces of data that a single query can return. You are also not doing anything inside of the do{}while() loop to get different data so the same data will be displayed 10 times. You can also use a LIMIT 10 in your query so that you only get the number of rows you are interested in. You can then using a simple while(){} loop.

 

 

Link to comment
Share on other sites

Based on the code in the first post in this thread, the following is the equivalent (with unused code removed and the two queries combined into one) -

 

<?php
// Check errors thing:
ini_set ('display_errors', 1);
error_reporting (E_ALL);
// End check errors thing.
?>
<?php
session_start();
// Start inculdes files:
include ("includes/config.php");
include ("includes/functions.php");
// End includes files.

// Login thing:
if(!isset($_SESSION['username']) || !isset($_SESSION['password'])){
   header("Location: index.php");
   exit; // prevent the remainder of the code on the page from being executed
}
?>
<link href="regstyle.css" rel="stylesheet" type="text/css">
<body class="body">
<?php

$result = mysql_query("SELECT username, money FROM users ORDER BY money DESC LIMIT 10");
$row = mysql_fetch_object($result);
echo "<ul>";
$i = 1;
while($row = mysql_fetch_object($result)){
echo  "<table width='50%' class='table' cellpadding='0' cellspacing='0'><tr><td class='header' colspan='4'><center>Money Blacklist</center></td></tr>
<tr><td colspan='1' class='forum'>Place:</td><td colspan='1' class='forum'>Username:</td><td colpan='1' class='forum'>Money:</td></tr>
<tr><td>{$i}</td><td><a href='profile.php/view_user={$row->username}'>{$row->username}</td><td>£{$row->money}</td></tr></table>";
$i++;
}
echo "</ul>";
?>
</body>

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.