Bman900 Posted June 20, 2009 Share Posted June 20, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/163056-upgraded-to-php-5-and-errors-galore/ Share on other sites More sharing options...
cunoodle2 Posted June 20, 2009 Share Posted June 20, 2009 Honestly take a look into rewriting that stuff and use php prepared statements. They are so much more secure. Quote Link to comment https://forums.phpfreaks.com/topic/163056-upgraded-to-php-5-and-errors-galore/#findComment-860377 Share on other sites More sharing options...
PFMaBiSmAd Posted June 20, 2009 Share Posted June 20, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/163056-upgraded-to-php-5-and-errors-galore/#findComment-860386 Share on other sites More sharing options...
phant0m Posted June 20, 2009 Share Posted June 20, 2009 you could use mysql_error() to get an error message Quote Link to comment https://forums.phpfreaks.com/topic/163056-upgraded-to-php-5-and-errors-galore/#findComment-860404 Share on other sites More sharing options...
Bman900 Posted June 20, 2009 Author Share Posted June 20, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/163056-upgraded-to-php-5-and-errors-galore/#findComment-860421 Share on other sites More sharing options...
PFMaBiSmAd Posted June 20, 2009 Share Posted June 20, 2009 Based on the actual code, something in or about your table is causing the queries to fail. If you add a debugging line of code - echo mysql_error(); after each line with a mysql_query(), you will learn why the query failed. Quote Link to comment https://forums.phpfreaks.com/topic/163056-upgraded-to-php-5-and-errors-galore/#findComment-860424 Share on other sites More sharing options...
Bman900 Posted June 21, 2009 Author Share Posted June 21, 2009 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()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/163056-upgraded-to-php-5-and-errors-galore/#findComment-860448 Share on other sites More sharing options...
PFMaBiSmAd Posted June 21, 2009 Share Posted June 21, 2009 That means that there are not 20 rows (counting starts at zero) in the result set. Any code that uses mysql_result() must first check how many rows were returned by the query. Quote Link to comment https://forums.phpfreaks.com/topic/163056-upgraded-to-php-5-and-errors-galore/#findComment-860452 Share on other sites More sharing options...
Bman900 Posted June 21, 2009 Author Share Posted June 21, 2009 But there are. Thats what I don't understand. As soon as I switch back to PHP 4.4 it works just like a designed it but as soon as I do PHP5 errors come up all over the place. Quote Link to comment https://forums.phpfreaks.com/topic/163056-upgraded-to-php-5-and-errors-galore/#findComment-860455 Share on other sites More sharing options...
trq Posted June 21, 2009 Share Posted June 21, 2009 You code is terrible (in any version). You need always check your queries succeed and return results before attempting to use them. Wrap your code in some checks. Quote Link to comment https://forums.phpfreaks.com/topic/163056-upgraded-to-php-5-and-errors-galore/#findComment-860457 Share on other sites More sharing options...
PFMaBiSmAd Posted June 21, 2009 Share Posted June 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/163056-upgraded-to-php-5-and-errors-galore/#findComment-860464 Share on other sites More sharing options...
Bman900 Posted June 21, 2009 Author Share Posted June 21, 2009 So would this work? <? if($content20Res) { $content20 = mysql_result($content1Res, 19, 0) } ?> Quote Link to comment https://forums.phpfreaks.com/topic/163056-upgraded-to-php-5-and-errors-galore/#findComment-860476 Share on other sites More sharing options...
trq Posted June 21, 2009 Share Posted June 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/163056-upgraded-to-php-5-and-errors-galore/#findComment-860564 Share on other sites More sharing options...
Bman900 Posted June 21, 2009 Author Share Posted June 21, 2009 can I jusr create a function to check my query? Quote Link to comment https://forums.phpfreaks.com/topic/163056-upgraded-to-php-5-and-errors-galore/#findComment-860826 Share on other sites More sharing options...
pkedpker Posted June 21, 2009 Share Posted June 21, 2009 ya why not create a function but why? you are not saving any room.. mysql_num_rows is like your function it also takes 1 line like what else can you do. Quote Link to comment https://forums.phpfreaks.com/topic/163056-upgraded-to-php-5-and-errors-galore/#findComment-860832 Share on other sites More sharing options...
Bman900 Posted June 21, 2009 Author Share Posted June 21, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/163056-upgraded-to-php-5-and-errors-galore/#findComment-860849 Share on other sites More sharing options...
Bman900 Posted June 22, 2009 Author Share Posted June 22, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/163056-upgraded-to-php-5-and-errors-galore/#findComment-861000 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.