Jump to content

Upgraded to PHP 5 and errors galore!


Bman900

Recommended Posts

I was working on a script that need PHP 5 so I did the upgrade but a major script I was working on before displays more errors than there are codes of lines!

 

Here is a little taste:

 

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /homepages/44/d272374679/htdocs/demo/include.php on line 8

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /homepages/44/d272374679/htdocs/demo/include.php on line 11

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /homepages/44/d272374679/htdocs/demo/include.php on line 14

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /homepages/44/d272374679/htdocs/demo/include.php on line 17

 

I noticed if I use msqli it works to a point but it doesn't pick up mysqli_result plus I don't want mysqli. Any one?

Link to comment
Share on other sites

The errors you posted mean that your mysql_query() failed and returned a FALSE value instead of a result resource. A query that works but has zero rows in the result set does return a result resource and does not produce those specific errors. Either there is a problem with the connection to the database server, a problem with selecting the database, a problem with the query syntax, or a problem with the data put into the query that is breaking the query.

 

Those specific errors also mean that your code has no error checking (check if something worked or not), error reporting/logging (output a meaningful user message when it does not work and log information about what happened so you can find and fix the problem), and error recovery (take an appropriate action when there is an error instead of blindly attempting to access nonexistent data) logic in it, because your code should not have gotten to the point of trying to retrieve data from a query that failed.

 

If your code 'worked' before the upgrade to php5, it is likely that it is doing something that is php configuration specific (there are very few incompatible code differences in using php4 code under php5) that would cause the queries to fail.

 

You would need to post your actual code for anyone here to be able to help you with what it is doing.

Link to comment
Share on other sites

Here is part of my code.

 

<?php
include("config.php");

mysql_connect("$dbhost", "$dbusername", "$dbpassword") or die(mysql_error());
mysql_select_db("$databasename") or die(mysql_error());

$surveyRes = mysql_query("SELECT surveyinput FROM surveylink");
$surveylink = mysql_result($surveyRes, 0, 0);

$emailRes = mysql_query("SELECT emailinput FROM email");
$email = mysql_result($emailRes, 0, 0);

$descRes = mysql_query("SELECT mdescription FROM meta_desc");
$description = mysql_result($descRes, 0, 0);

$mkeyRes = mysql_query("SELECT mkeywords FROM meta_keys");
$metakeywords = mysql_result($mkeyRes, 0, 0);

$acheckRes = mysql_query("SELECT acheck FROM awebercheck");
$webcheck = mysql_result($acheckRes, 0, 0); ?>

Link to comment
Share on other sites

Ok here is the error I get:

 

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 19 on MySQL result index 62 in /homepages/44/d272374679/htdocs/draft/includepages.php on line 80

 

This doesn't make sense since it worked with Php 4.4

 

Here is the exact code I have on that line:

 

<?php $content20 = mysql_result($content1Res, 19, 0) or die (mysql_error()); ?>

Link to comment
Share on other sites

It's likely that your code is blindly being executed even in the case when no results are expected but the Warning error messages are being hidden due to the settings in the php4 configuration.

 

You need to fix your code, because each statement that generates an error (even if the end error message is hidden) takes at least 10 times longer to execute because php must still go through the error response code to figure out what to do, than if the code is corrected and does not generate the error in the first place.

Link to comment
Share on other sites

No. You need to re-read PFMaBiSmAd's post.

 

Also, to check your queries succeed and actually return a result you would use something like...

 

if ($surveyRes = mysql_query("SELECT surveyinput FROM surveylink")) {
  if (mysql_num_rows($surveyRes)) {
    $surveylink = mysql_result($surveyRes, 0, 0);
  }
}

 

You might also want to actually check how many result you got before you start blindly trying to use row 19.

Link to comment
Share on other sites

Alright, but i still need to fix me code. So am going to do a check to make sure there are 20 rows than dumb everything into an array and use that to put information into variables for me to use. Does that sound like a good plan?

Link to comment
Share on other sites

Alright I fixed most of my code but I am running into one hell of a mountain. Something get royaly messed up as soon as I enter into a folder that links back to my include file like. (../include.php) Am thinking it is a connection issue because my code and database is fine in the include file. I do connect to a databse in the include file by getting variables out of config.php in my include.php file. Should I be making a connection before I include a file from outside of a folder. The weird thing is that it works perfectly in my root directory. Anything will help me.

 

Alright I found out that if I make the connection inside my include file and not use variables stored in config.php it works but that still doesn't make sense. include.php include config.php from the same directory. Than admin.php includes include.php from ../  WHat am I missing?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.