Catchable Fatal Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Catchable Fatal Error

Post by psychotomus »

Catchable fatal error: Object of class stdClass could not be converted to string in /mounted-storage/home45b/sub001/sc18478-RGIJ/simsportal.net/fanfic-manage.php on line 95

line 95 is time() how do i fix?

Code: Select all

mysql_query("INSERT INTO fanfic_chapters(
					title,
					fanfic_id,
					chapter,
					fanfic,
					the_date
					)
					VALUES (
					'$chapter_title',
					'$fanfic->id',
					'1',
					'$fanfic',
					'" . time() . "'
					)") or die(mysql_error());
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

does 'time()' not work, or no quotes at all? if all else fails, put it into a variable beforehand...

Code: Select all

$time = time();
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

I don't think time() is working. i put echo time() and it gives me same error on the next line number.
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

ok. i did what you said and it still errors on same line 95 where $time is I even replaced $time with 111111 and still same error =(

Code: Select all

$time = time();
			mysql_query("INSERT INTO fanfic_chapters(
					title,
					fanfic_id,
					chapter,
					fanfic,
					the_date
					)
					VALUES (
					'$chapter_title',
					'$id',
					'1',
					'$fanfic',
					'$time'
					)") or die(mysql_error());
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

Is it just the current date and time you are trying to enter?
Is the field type DATE, DATETIME or TIMESTAMP?

if so let mysql do it with the NOW() or the UNIX_TIMESTAMP() function, dependent on the field type.

Code: Select all

 mysql_query("INSERT INTO fanfic_chapters( 
                                        title, 
                                        fanfic_id, 
                                        chapter, 
                                        fanfic, 
                                        the_date 
                                        ) 
                                        VALUES ( 
                                        '$chapter_title', 
                                        '$id', 
                                        '1', 
                                        '$fanfic', 
                                        NOW() 
                                        )") or die(mysql_error());
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Catchable fatal error: Object of class stdClass could not be converted to string
It's not a problem with mysql or the query in general. There's no stdClass in mysql but in php.

Code: Select all

<?php
$x = new stdClass;
echo ".. $x ..";
Catchable fatal error: Object of class stdClass could not be converted to string in ... on line 3
try

Code: Select all

echo 'Debug: $chapter_title :', gettype($chapter_title), "</div>\n";
echo 'Debug: $id :', gettype($id), "</div>\n";
echo 'Debug: $fanfic :', gettype($fanfic), "</div>\n";

mysql_query("INSERT INTO fanfic_chapters(
What does it print?
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

A lot of time the error isn't on the exact line reported but on a previous line. I am thinking that $fanfic or one of the other variables you are using is an object instead of a string.
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

it says fanfic is object...

Code: Select all

$fanfic = mysql_real_escape_string(nl2br(htmlspecialchars(str_replace("\'", "'", strip_tags($_POST['textFanFic'])))));
		$title =  mysql_real_escape_string(htmlspecialchars(str_replace("\'", "'", $_POST['textTitle'])));
		$chapter_title =  mysql_real_escape_string(htmlspecialchars(str_replace("\'", "'", $_POST['textChapterTitle'])));
		$cat =  htmlspecialchars(str_replace("\'", "'", $_POST['select2']));
		if(strlen($title) < 1)
			$eRR = 'Enter a title for your poem.<br>';
		if(strlen($fanfic) < 100)
			$eRR = 'Fan Fic must be at least 100 characters long';

		if ($eRR == "")
		{
			$result = mysql_query("SELECT cat FROM fanfic_cats WHERE id='$id'") or die(mysql_error());
			$cat = mysql_fetch_object($result);
			mysql_query("INSERT INTO fanfics(
					title,
					username,
					cat
					)
					VALUES (
					'$title',
					'$username',
					'$cat->cat'
					)") or die(mysql_error());
					
			mysql_query("UPDATE users SET user_fanfics='user_fanfics+1' WHERE username='$username'") or die(mysql_error());
			mysql_query("UPDATE fanfic_cats SET fanfics='fanfics+1' WHERE id='$cat'") or die(mysql_error());
			$result = mysql_query("SELECT id FROM fanfics ORDER BY id DESC LIMIT 1") or die(mysql_error());
			$fanfic = mysql_fetch_object($result);
			$id = $fanfic->id;
			echo 'Debug: $chapter_title :', gettype($chapter_title), "</div>\n"; 
echo 'Debug: $id :', gettype($id), "</div>\n"; 
echo 'Debug: $fanfic :', gettype($fanfic), "</div>\n";
			$time = time();
			mysql_query("INSERT INTO fanfic_chapters
					(
					title,
					fanfic_id,
					chapter,
					fanfic,
					the_date
					)
					VALUES 
					(
					'$chapter_title',
					'$id',
					'1',
					'$fanfic',
					'11111'
					)") or die(mysql_error());
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

And it's right
psychotomus wrote:$fanfic = mysql_fetch_object($result);
mysql_query("INSERT INTO fanfic_chapters
(
title,
fanfic_id,
chapter,
fanfic,
the_date
)
VALUES
(
'$chapter_title',
'$id',
'1',
'$fanfic',
'11111'
)") or die(mysql_error());
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

can't believe i overlooked that =(
Post Reply