PDA

View Full Version : HELP! Unexplaned deaths in iBook 2.0!


Illynova
Sat 12th May '01, 7:28pm
ll righty now, I have a very weird problem. My script written in PHP, Inca Guest Book 2.0 uses mySQL to store its data. So far, so good.
Randomly, for absolutely no reason whatsoever. It'll print the following error:

Warning: *Supplied argument is not a valid MySQL result resource in

Here's the weird part. If I reload it 5-10 times, it'll work once or twice, then die again. If I sign the book, it'll work, once or twice. Could someone shed some light on this problem.
Here's the source:


<html>
<head>
<title>iGuest Book 2.0: Preview</title>
</head>
<body bgcolor=c0c0c0>
<?php
// Start the timer
$speed_check_start = exec_time();

// Init variables
$link_id = 0;

// Include files
include("/local/httpd/htdocs/tests/db_common.php4");
include("/local/httpd/htdocs/ibook/test/variables.php4");

//--------------------------------------------------// Branch point //------------------------------------------------------------------
if ($action == "view") {
displayGuestBook(0);
print "Hello!";
}
else if ($action == "sign") {
include("/local/httpd/htdocs/ibook/test/sign_htm.php4");
}
else if ($action == "process") {

}
else {
print "<font face=$text_main><b>Warning:</b> Missing action clause.<br></font>";
}

//--------------------------------------------------// Clean-up work //------------------------------------------------------------------

$speed_check_finish = exec_time();
$speed_check_runtime = $speed_check_finish - $speed_check_start;

if ($speed_check_runtime < 0) {
$speed_check_runtime += 1;
}

echo "It took: $speed_check_runtime seconds to make this page.<br>\n";
//--------------------------------------------------// Init mySQL + Pointer //------------------------------------------------------------------
function startup() {
// Start-up
global $link_id;
$link_id = db_connect();

// If there is an error, then quit.
if(!$link_id) die (sql_error());

// Select the database to use.
mysql_select_db($dbname, $link_id);
return $link_id;
}

//--------------------------------------------------// Display GB Entries //------------------------------------------------------------------
function displayGuestBook($page = 0) {

/* Temporary fix for bad mySQL pointer. Doesn't really seem to be working though. */

// Start-up
$link_id = db_connect();


// If there is an error, then quit.
if(!$link_id) die (sql_error());

// Select the database to use.
mysql_select_db($dbname, $link_id);

// Start the output

print "<h1>iGuest Book 2.0</h1><hr>";
print "Do you want to sign the guest book? <a href=\"http://inca.cc.uic.edu/ibook/test/ibook.php4?action=sign\">Sign</a><br><br><br>";

// Build and execute the mySQL query to get entry data
$query = "SELECT name, signdate, email, www, gender, fromwhere, usercomments FROM entries ORDER BY entryid DESC";

if (($link_id == 0) || ($link_id == -1)) {
print "<b>Warning:</b> Invalid mySQL connection id, when attempting to get entry data.<br>";
}

$result = mysql_query("$query");

// Now lets loop through the results and format + print to the browser
while ($selectdata = mysql_fetch_array($result)) {
$entryid = $selectdata["entryid"];
$name = $selectdata["name"];
$date = $selectdata["signdate"];
$email = $selectdata["email"];
$www = $selectdata["www"];
$gender = $selectdata["gender"];
$location= $selectdata["fromwhere"];
$commment= $selectdata["usercomments"];
// Print the output!
print "
<div align=center>
<table border=1 cellpadding=2 cellspacing=0 width=510 height=1>
<tr>
<td width=79 height=1 bgcolor=#808080><font size=2 face=Arial><b>Name</b></font></td>
<td width=431 height=1 bgcolor=#808080><font face=Verdana size=2>&nbsp;<a href=mailto:$email>$name</a></font></td>
</tr>
<tr>
<td width=79 height=1 bgcolor=#999999><font size=2 face=Arial><b>Signed
on:</b></font></td>
<td width=431 height=1 bgcolor=#999999><font face=Verdana size=2>&nbsp;$date</font></td>
</tr>
<tr>
<td width=79 height=1 bgcolor=#808080><font size=2 face=Arial><b>Homepage</b></font></td>
<td width=431 height=1 bgcolor=#808080><font face=Verdana size=2>&nbsp;<a href=$www>$www</a></font></td>
</tr>
<tr>
<td width=79 height=1 bgcolor=#999999><font size=2 face=Arial><b>From</b></font></td>
<td width=431 height=1 bgcolor=#999999><font face=Verdana size=2>&nbsp;$location</font></td>
</tr>
<tr>
<td width=510 height=11 colspan=2 valign=top bgcolor=#808080><b><font face=Arial size=2>Comments:</b>&nbsp;&nbsp;&nbsp;$commment
</font></b></td>
</tr>
</table>
<br>---------<br><br>
</div>

";

}
print" <hr><p align=center>Powered by iBook v2.0. (c) 2001 Scott MacDonald all rights reserved.</p>";
}

function exec_time() {
$speed_check_mtime = explode(" ",microtime());
$speed_check_msec = (double) $speed_check_mtime[0];
$speed_check_sec = (double) $speed_check_mtime[1];
return +speed_check_sec + $speed_check_msec;
}


?>


(By the way, the global $link_id is depreciated. Also, in desperation, I tried moving the code to connect to mySQL from the function into the actual core.

Please, please help me!