Page 1 of 1

Catchable Fatal Error

Posted: Sun Mar 11, 2007 11:09 pm
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());

Posted: Mon Mar 12, 2007 12:26 am
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();

Posted: Mon Mar 12, 2007 12:35 am
by psychotomus
I don't think time() is working. i put echo time() and it gives me same error on the next line number.

Posted: Mon Mar 12, 2007 12:37 am
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());

Posted: Mon Mar 12, 2007 2:46 am
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());

Posted: Mon Mar 12, 2007 3:11 am
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?

Posted: Mon Mar 12, 2007 5:07 am
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.

Posted: Mon Mar 12, 2007 4:16 pm
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());

Posted: Mon Mar 12, 2007 4:22 pm
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());

Posted: Mon Mar 12, 2007 6:50 pm
by psychotomus
can't believe i overlooked that =(