View Full Version : php just stopped accessing my database...?

01-07-2008, 12:42 AM
I've had a quote database that worked fine for 2 years now. About 2 months ago it just stopped working and I am at a loss as to why. There was nothing wrong with my scripting, because it worked for 2 years. The database still exists and has entries. My home page can count them and can access my updates table. But any time it tries to search for quotes on my sort page it comes back with a zero result. No errors or anything - just a zero result when I have roughly 600 quotes. If I try to circumvent the sorting page and go directly to a quote.php specifying a specific source I still get nothing.

I've looked over the pages to see if it got hacked and something changed, I've moved my database to a new host and I've uploaded pages from my hard drive to verify they weren't changed. Still zero result. I am completely baffled - was there a recent upgrade to php software that renders the code ineffective? That's seriously the only thing I can imagine at this point because I'm at such a loss

I've linked to each of my pages in this entry and the following is my current coding:

home page (http://www.eidolon-solstice.net/eucatastrophe/home.php):

$result=mysql_query ("SELECT title, ID FROM $category_table ORDER BY title ASC");
if ($row=mysql_fetch_array($result)) {
do { ?>
<a href="sort.php?action=<?=$row["ID"]?>"><?=$row["title"]?></a><br>
<? } while($row = mysql_fetch_array($result));
} ?>
<p><a href="home.php" target="page">home</a></p>

$resultcount=mysql_query("SELECT ID FROM $table");
$num=mysql_numrows($resultcount); ?> // works just fine

<p>blah blah text <? $num ?> blah blah</p> //works just fine

$result = mysql_query("SELECT * FROM $update_table ORDER BY timestamp DESC");

while ($row = mysql_fetch_array($result)) {
$month = date("m",$row["timestamp"]);
$day = date("d",$row["timestamp"]);
$year = date("y",$row["timestamp"]);
$updates = $row["updates"];
$upID = $row["ID"];

print "<p>~<b>$month-$day-$year</b> $updates</p>"; //works just fine

print "<h3 align=\"right\">";

print "</h3><hr>\n";

sorting page (http://www.eidolon-solstice.net/eucatastrophe/sort.php?action=5):

$result=mysql_query("SELECT DISTINCT source, name FROM $table WHERE reatID='$action' ORDER BY source ASC");
$num=mysql_numrows($result); //suddenly returns no result with no errors

<table border="0" cellspacing="0" cellpadding="5">

while ($i < $num) {

$result2=mysql_query("SELECT ID FROM $table WHERE source='$source'AND reatID='$action'");
$num2=mysql_numrows($result2); // suddenly returns no result

echo "<td><a href=\"quote.php?id=$source\">";
if ($name !=""){
echo "$name</a></td>";
} else {
echo "$source</a></td>"; }

echo "<td><center>$num2</center></td></tr>";


$result3=mysql_query("SELECT * FROM $table WHERE reatID='$action'");
$num3=mysql_numrows($result3); // suddenly returns a zero result

echo "<td><a href=\"category.php?id=$action\">view all</a></td>";
echo "<td><center>$num3</center></td></tr>";
echo "</table></div>";

quote page (http://www.eidolon-solstice.net/eucatastrophe/quote.php?action=Buffy):

$result=mysql_query ("SELECT * FROM $table WHERE source='$id' ORDER BY quote ASC");
$num=mysql_numrows($result); // no result returns

while ($i < $num) {

echo "<p>$quote<br>";

if ($title !=""){
echo " :: $title";

if ($comments !=""){
echo " ($comments)</p>\n";
} else {
echo "</p>\n";

any ideas? help?

01-07-2008, 01:05 AM
...WHERE reatID='$action'

...WHERE source='$id'

Your code is apparently dependent on register_globals being on (unless code that you did not post is setting $action and $id in the second and third pieces of code.)

Register globals have caused a tremendous amount of security problems and wasted time (something like the y2k problem a few years ago.) They were a huge blunder and thankfully, they are gone in php6. Unfortunately, even though they were turned off by default in 2002 and no new code, tutorials, books... should have been written after that point in time that relied on them being on, a LOT of code was written after then that relies on register_globals.

If your hosting company turned register_globals off, either deliberately or inadvertently when they upgraded php, they should have notified all their customers of the change/upgrade.

01-07-2008, 05:37 AM
I checked, my host is running PHP version 5.2.5 with register_globals off.

$action and $id are defined in the url by links from previous pages. This is going to sound stupid but does that mean the code is reliant on register_globals needs to be on?

01-07-2008, 05:53 AM
If you have no lines of code that look like -

$action = $_GET['action']; // get the action=xxx parameter from the end of the url.

// and -

$id = $_GET['id']; // get the id=xxx parameter from the end of the url.

Then yes, that code is dependent on register globals being on.

Because register globals have been eliminated in PHP6, take the time now to fix your code to work without register_globals. (If your host permits you to turn on register_globals in a .htaccess file or a local php.ini file, you could turn them on temporarily while you fix your code, but you must fix it before php6 comes out.)

01-07-2008, 06:09 AM
thank you!!!
That was exactly what I needed. And so easy to fix.