PDA

View Full Version : Fatal error: Call to a member function on a non-object


SilentK
06-16-2005, 07:57 PM
I have a query that used to work before I installed 3.5 Now I get this error message whenever I load the page
Fatal error: Call to a member function on a non-object in /./././htdocs/widget.php on line 5

This is the contents of widget.php

<?php
chdir('/./././htdocs/forums');
require 'global.php';

$latestThreads = $DB_site->query("
SELECT *
FROM " . TABLE_PREFIX . "thread AS thread
WHERE thread.visible = 1
ORDER BY dateline DESC
LIMIT 5
");
$num_rows = $DB_site->num_rows($latestThreads);
while($row = $DB_site->fetch_array($latestThreads) )
{
echo('<a href="http://www.xblteams.com/forums/showthread.php?t=' . $row[threadid] . '">' . $row[title] . '</a><br />');
}

?>

That worked before 3.5. What changed? and what do I need to change to make it work?

Also I would like to get it so the links are formatted like this

<a href="javascript:widget.openURL('http://www.xblteams.com/forums/showthread.php?t=put thread id here')"></a>


I've tried

echo('<a href="javascript:widget.openURL('http://www.xblteams.com/forums/showthread.php?t=' . $row[threadid] . ' ')">' . $row[title] . '</a><br />');


but I get a parse error.
Thanks in advance.

Andreas
06-16-2005, 08:05 PM
That worked before 3.5. What changed? and what do I need to change to make it work?


$DB_site is now $db.

And you should use query_read/query_write instead of just query depending if you are reading from or writing to the database.


echo('<a href="javascript:widget.openURL(\'http://www.xblteams.com/forums/showthread.php?t=' . $row[threadid] . '\')">' . htmlentities($row[title]) . '</a><br />');

should work.

The htmlspecialchars_uni() is necesarry, otherwise you create an XSS vulnerbilitie.

SilentK
06-16-2005, 08:51 PM
Hmmm that fixed the error and appears to be formatting the link correctly. What I am trying to do is create a widget for mac os 10.4 so far the only way I have found to get a widget to open up a link in safari is javascript:widget.openURL

From what I can tell the php file is doing it's job perfectly.
Here's an example of a link that it's pumping out.

<a href="javascript:widget.openURL('http://www.xblteams.com/forums/showthread.php?t=4257')">Call of Duty screenshots</a>

That should work because I have tested.
<a href="javascript:widget.openURL('http://www.xblteams.com/')">Xblteams.com</a>

Directly inside the widge and it works. I am guessing there must be an issue with the way I am loading the links into the widget.

here's the body of the widget

<body background="Default.png">
<table cellpadding="20">
<tr><td>
<IFRAME SRC="http://www.xblteams.com/widget.php" WIDTH=180 HEIGHT=240>
</IFRAME>
</td></tr></table>
</body>

From the testing I have done the iframe is causing the problem. The reason I think this is I created a file with just <a href="javascript:widget.openURL('http://www.xblteams.com/')">Xblteams.com</a>

and loaded it via an Iframe and it didn't work either. By not working I mean when I click the link nothing happens.

Is there a better way to load the links in?
widgets support javascript, and html.