While Loop Issues

While Loop Issues

am 22.12.2007 18:04:19 von MKruer

I am having issues with a while loop in a modified script. It gives me
the error "Fatal error: Cannot access empty property in fb2phpbb2.php
on line 146" If i comment out the loop. The script does populate the
table. Because the script was designed for php 4.x, I think its just a
syntactical issue. More info can be found at
http://www.phpbb.com/community/viewtopic.php?f=10&t=588149&p =3563595#p3563595

-TIA-

[Code]
while ( $row = mysql_fetch_object( $result ) ) {
// remove extra slashes
$subject = stripslashes( $row->subject );
// Some messages still had the single quote in them without a \
// which was causing import problems so we
// removed the single quote and replaced it with HTML for the
quote
$subject = preg_replace ('/\'/', '\\\'', $subject);
$query="INSERT INTO {$phpbb_dbprefix}topics"
." (topic_id, forum_id, topic_poster, topic_title, topic_time,"
." topic_views, topic_replies, topic_status, topic_vote,
topic_type,"
." topic_first_post_id, topic_last_post_id, topic_moved_id)"
." VALUES ('$row->id', '$row->catid', '$row->userid',
'$subject', '$row->time',"
." '$row->hits', '$row->reply', '$row->locked', '0', '',"
." '$row->min', '$row->max', '0')";
$updateresult = mysql_query($query) or die("
Invalid
query:
$query
" . mysql_error());
}
mysql_free_result($result);

[/Code]

Re: While Loop Issues

am 22.12.2007 18:46:07 von luiheidsgoeroe

On Sat, 22 Dec 2007 18:04:19 +0100, wrote:

> I am having issues with a while loop in a modified script. It gives me=

> the error "Fatal error: Cannot access empty property in fb2phpbb2.php
> on line 146" If i comment out the loop. The script does populate the
> table. Because the script was designed for php 4.x, I think its just a=

> syntactical issue. More info can be found at
> http://www.phpbb.com/community/viewtopic.php?f=3D10&t=3D5881 49&p=3D356=
3595#p3563595
>
> -TIA-
>
> [Code]
> while ( $row =3D mysql_fetch_object( $result ) ) {
> // remove extra slashes
> $subject =3D stripslashes( $row->subject );
> // Some messages still had the single quote in them without a \
> // which was causing import problems so we
> // removed the single quote and replaced it with HTML for the
> quote
> $subject =3D preg_replace ('/\'/', '\\\'', $subject);
> $query=3D"INSERT INTO {$phpbb_dbprefix}topics"
> ." (topic_id, forum_id, topic_poster, topic_title, topic_time,"=

> ." topic_views, topic_replies, topic_status, topic_vote,
> topic_type,"
> ." topic_first_post_id, topic_last_post_id, topic_moved_id)"
> ." VALUES ('$row->id', '$row->catid', '$row->userid',
> '$subject', '$row->time',"
> ." '$row->hits', '$row->reply', '$row->locked', '0', '',"
> ." '$row->min', '$row->max', '0')";
> $updateresult =3D mysql_query($query) or die("
Invalid
> query:
$query
" . mysql_error());
> }
> mysql_free_result($result);
>
> [/Code]

First of all: mysql_real_escape_string()
Also, try to use curly braces around 'complex' variables in strings.
Lastly, probably you don't even need a loop and you can do this with a =

simple 'INSERT .... SELECT...' query.
-- =

Rik Wasmus

Re: While Loop Issues

am 22.12.2007 23:04:04 von MKruer

On Dec 22, 9:46 am, "Rik Wasmus" wrote:
> On Sat, 22 Dec 2007 18:04:19 +0100, wrote:
> > I am having issues with a while loop in a modified script. It gives me
> > the error "Fatal error: Cannot access empty property in fb2phpbb2.php
> > on line 146" If i comment out the loop. The script does populate the
> > table. Because the script was designed for php 4.x, I think its just a
> > syntactical issue. More info can be found at
> >http://www.phpbb.com/community/viewtopic.php?f=10&t=588149& p=3563595#...
>
> > -TIA-
>
> > [Code]
> > while ( $row = mysql_fetch_object( $result ) ) {
> > // remove extra slashes
> > $subject = stripslashes( $row->subject );
> > // Some messages still had the single quote in them without a \
> > // which was causing import problems so we
> > // removed the single quote and replaced it with HTML for the
> > quote
> > $subject = preg_replace ('/\'/', '\\\'', $subject);
> > $query="INSERT INTO {$phpbb_dbprefix}topics"
> > ." (topic_id, forum_id, topic_poster, topic_title, topic_time,"
> > ." topic_views, topic_replies, topic_status, topic_vote,
> > topic_type,"
> > ." topic_first_post_id, topic_last_post_id, topic_moved_id)"
> > ." VALUES ('$row->id', '$row->catid', '$row->userid',
> > '$subject', '$row->time',"
> > ." '$row->hits', '$row->reply', '$row->locked', '0', '',"
> > ." '$row->min', '$row->max', '0')";
> > $updateresult = mysql_query($query) or die("
Invalid
> > query:
$query
" . mysql_error());
> > }
> > mysql_free_result($result);
>
> > [/Code]
>
> First of all: mysql_real_escape_string()
> Also, try to use curly braces around 'complex' variables in strings.
> Lastly, probably you don't even need a loop and you can do this with a
> simple 'INSERT .... SELECT...' query.
> --
> Rik Wasmus

That still does not answer my question of what is wrong with the loop.
What I posted is a simple while loop. there are other parts of the
code that are much more complex that I simply cant update the query
with a replace string SQL query.

-Matt-

Re: While Loop Issues

am 22.12.2007 23:42:47 von MKruer

On Dec 22, 2:04 pm, MKr...@gmail.com wrote:
> On Dec 22, 9:46 am, "Rik Wasmus" wrote:
>
>
>
> > On Sat, 22 Dec 2007 18:04:19 +0100, wrote:
> > > I am having issues with a while loop in a modified script. It gives me
> > > the error "Fatal error: Cannot access empty property in fb2phpbb2.php
> > > on line 146" If i comment out the loop. The script does populate the
> > > table. Because the script was designed for php 4.x, I think its just a
> > > syntactical issue. More info can be found at
> > >http://www.phpbb.com/community/viewtopic.php?f=10&t=588149& p=3563595#...
>
> > > -TIA-
>
> > > [Code]
> > > while ( $row = mysql_fetch_object( $result ) ) {
> > > // remove extra slashes
> > > $subject = stripslashes( $row->subject );
> > > // Some messages still had the single quote in them without a \
> > > // which was causing import problems so we
> > > // removed the single quote and replaced it with HTML for the
> > > quote
> > > $subject = preg_replace ('/\'/', '\\\'', $subject);
> > > $query="INSERT INTO {$phpbb_dbprefix}topics"
> > > ." (topic_id, forum_id, topic_poster, topic_title, topic_time,"
> > > ." topic_views, topic_replies, topic_status, topic_vote,
> > > topic_type,"
> > > ." topic_first_post_id, topic_last_post_id, topic_moved_id)"
> > > ." VALUES ('$row->id', '$row->catid', '$row->userid',
> > > '$subject', '$row->time',"
> > > ." '$row->hits', '$row->reply', '$row->locked', '0', '',"
> > > ." '$row->min', '$row->max', '0')";
> > > $updateresult = mysql_query($query) or die("
Invalid
> > > query:
$query
" . mysql_error());
> > > }
> > > mysql_free_result($result);
>
> > > [/Code]
>
> > First of all: mysql_real_escape_string()
> > Also, try to use curly braces around 'complex' variables in strings.
> > Lastly, probably you don't even need a loop and you can do this with a
> > simple 'INSERT .... SELECT...' query.
> > --
> > Rik Wasmus
>
> That still does not answer my question of what is wrong with the loop.
> What I posted is a simple while loop. there are other parts of the
> code that are much more complex that I simply cant update the query
> with a replace string SQL query.
>
> -Matt-

Never mind. i found the issue. it was problem with the Select
statement above. By itself its fine but in a while loop, it blew it
up.

Re: While Loop Issues

am 23.12.2007 16:14:41 von luiheidsgoeroe

On Sat, 22 Dec 2007 23:42:47 +0100, wrote:
> On Dec 22, 2:04 pm, MKr...@gmail.com wrote:
>> On Dec 22, 9:46 am, "Rik Wasmus" wrote:
>> > > [Code]
>> > > while ( $row =3D mysql_fetch_object( $result ) ) {
>> > > // remove extra slashes
>> > > $subject =3D stripslashes( $row->subject );
>> > > // Some messages still had the single quote in them without a=
\
>> > > // which was causing import problems so we
>> > > // removed the single quote and replaced it with HTML for the=

>> > > quote
>> > > $subject =3D preg_replace ('/\'/', '\\\'', $subject);
>> > > $query=3D"INSERT INTO {$phpbb_dbprefix}topics"
>> > > ." (topic_id, forum_id, topic_poster, topic_title, =

>> topic_time,"
>> > > ." topic_views, topic_replies, topic_status, topic_vote,
>> > > topic_type,"
>> > > ." topic_first_post_id, topic_last_post_id, topic_moved_id=
)"
>> > > ." VALUES ('$row->id', '$row->catid', '$row->userid',
>> > > '$subject', '$row->time',"
>> > > ." '$row->hits', '$row->reply', '$row->locked', '0', '',"
>> > > ." '$row->min', '$row->max', '0')";
>> > > $updateresult =3D mysql_query($query) or die("
Invalid=

>> > > query:
$query
" . mysql_error());
>> > > }
>> > > mysql_free_result($result);
>>
>> > > [/Code]
>>
>> > First of all: mysql_real_escape_string()
>> > Also, try to use curly braces around 'complex' variables in strings=
..
>> > Lastly, probably you don't even need a loop and you can do this wit=
h a
>> > simple 'INSERT .... SELECT...' query.
>> > --
>> > Rik Wasmus
>>
>> That still does not answer my question of what is wrong with the loop=
..
>> What I posted is a simple while loop. there are other parts of the
>> code that are much more complex that I simply cant update the query
>> with a replace string SQL query.
>>
> Never mind. i found the issue. it was problem with the Select
> statement above. By itself its fine but in a while loop, it blew it
> up.


You seem to be obsessed with the loop. Don't be. Without a loop it still=
=

would've produced the same error.


-- =

Rik Wasmus