talmik Posted October 21, 2012 Share Posted October 21, 2012 My old scripts suddenly dont work now that my server upgraded to php 5 for example This error- Warning: mysql_result() expects parameter 2 to be long, string given in /home/plegend/public_html/entry.php on line 165 This code- $roomname = mysql_result($currentroom, '$roomnumber', "name"); What is differant now? Quote Link to comment https://forums.phpfreaks.com/topic/269754-using-old-scripts-on-php5/ Share on other sites More sharing options...
Pikachu2000 Posted October 22, 2012 Share Posted October 22, 2012 (edited) Clearly, the second parameter is expected to be long, but you've given it a string value. Have you echoed it to see what exactly it is? http://us3.php.net/manual/en/function.mysql-result.php Edited October 22, 2012 by Pikachu2000 Quote Link to comment https://forums.phpfreaks.com/topic/269754-using-old-scripts-on-php5/#findComment-1386834 Share on other sites More sharing options...
Barand Posted October 22, 2012 Share Posted October 22, 2012 Doesn't matter what it contains - as it is in single quotes it is just the string '$roomnumber'. Remove the quotes. And I can't believe it worked in older versions either. Quote Link to comment https://forums.phpfreaks.com/topic/269754-using-old-scripts-on-php5/#findComment-1386836 Share on other sites More sharing options...
Pikachu2000 Posted October 22, 2012 Share Posted October 22, 2012 Didn't even notice those. So, yeah, it's a string. And I agree, that code must never have worked. Quote Link to comment https://forums.phpfreaks.com/topic/269754-using-old-scripts-on-php5/#findComment-1386838 Share on other sites More sharing options...
talmik Posted October 22, 2012 Author Share Posted October 22, 2012 Removing the quotes sadly does nothing. It did work before, have been using the code fine for about 4 years Quote Link to comment https://forums.phpfreaks.com/topic/269754-using-old-scripts-on-php5/#findComment-1386841 Share on other sites More sharing options...
ManiacDan Posted October 22, 2012 Share Posted October 22, 2012 The second argument to mysql_result is a number. It must be a number. You originally had the string '$roomnumber'. Are you saying that once you actually use the variable $roomnumber it's giving the same error? Try intval($roomnumber). Quote Link to comment https://forums.phpfreaks.com/topic/269754-using-old-scripts-on-php5/#findComment-1386885 Share on other sites More sharing options...
PFMaBiSmAd Posted October 22, 2012 Share Posted October 22, 2012 I'm going to guess it 'worked' because a non-numerical string, treated as a number, is zero. What exactly is your query and code leading up to that point? Are you actually trying to fetch something other than a row 0 value? Quote Link to comment https://forums.phpfreaks.com/topic/269754-using-old-scripts-on-php5/#findComment-1386887 Share on other sites More sharing options...
ManiacDan Posted October 22, 2012 Share Posted October 22, 2012 I think even a non-numeric string will throw an error, since these lower-level c functions tend to be strict. Quote Link to comment https://forums.phpfreaks.com/topic/269754-using-old-scripts-on-php5/#findComment-1386951 Share on other sites More sharing options...
talmik Posted October 22, 2012 Author Share Posted October 22, 2012 Thanks for your comments guys. This is the full section of code $roomnumber = mysql_result($currentuser, 0, "currentroom"); $currentroom = mysql_query("SELECT * FROM rooms WHERE number = $roomnumber LIMIT 1"); $roomname = mysql_result($currentroom, '$roomnumber', "name"); $roomname = explode(" ", $roomname); $roomname = $roomname[0]; $roomdescription = mysql_result($currentroom, 0, "description"); If I delete the line in question, the site works but it does not work correctly. It is basically calling from a list of rooms which are each named and number Quote Link to comment https://forums.phpfreaks.com/topic/269754-using-old-scripts-on-php5/#findComment-1387089 Share on other sites More sharing options...
Barand Posted October 22, 2012 Share Posted October 22, 2012 Even if roomnumber were numeric, as you only ever select a single row in that query, any roomnumber other than 0 would give an error. We can't see the previous query but it looks as though you have a query to get a roomnumber and then another query using that to get the room details. You should be doing all that in a single query using a JOIN. Quote Link to comment https://forums.phpfreaks.com/topic/269754-using-old-scripts-on-php5/#findComment-1387091 Share on other sites More sharing options...
PFMaBiSmAd Posted October 23, 2012 Share Posted October 23, 2012 Also, mysql_result is the slowest way of retrieving data because it performs a data seek, then a fetch. You should just use a mysql_fetch_assoc or mysql_fetch_row statement. Quote Link to comment https://forums.phpfreaks.com/topic/269754-using-old-scripts-on-php5/#findComment-1387109 Share on other sites More sharing options...
talmik Posted October 23, 2012 Author Share Posted October 23, 2012 Sadly I am not a programmer, I had these scripts custom made for me years ago. I cant even find a host who still uses the older php lol Quote Link to comment https://forums.phpfreaks.com/topic/269754-using-old-scripts-on-php5/#findComment-1387110 Share on other sites More sharing options...
ManiacDan Posted October 23, 2012 Share Posted October 23, 2012 These scripts were poorly written, even "back then." This line, for example, is wrong and has always been wrong. It was only through a fluke of multiple overlapping layers of wrong that it managed to work in the first place. Quote Link to comment https://forums.phpfreaks.com/topic/269754-using-old-scripts-on-php5/#findComment-1387120 Share on other sites More sharing options...
PFMaBiSmAd Posted October 23, 2012 Share Posted October 23, 2012 (edited) What is differant now? Aside from a Warning message, the lines of code you have posted should be producing the same result as before, Either php5 introduced that Warning message for the parameter type or the code was always producing the error, but it was hidden due to the error_reporting or display_errors/log_errors settings. Ignoring the Warning message, what else isn't working? What output are you getting v.s. what you expect? Edited October 23, 2012 by PFMaBiSmAd Quote Link to comment https://forums.phpfreaks.com/topic/269754-using-old-scripts-on-php5/#findComment-1387121 Share on other sites More sharing options...
PFMaBiSmAd Posted October 23, 2012 Share Posted October 23, 2012 I just tried your code for one of my tables/columns, and along with that Warning about the parameter type, it doesn't fetch any data. If you change that errant parameter from '$roomnumber' to a 0 (zero), your code will fetch the value from the result of the query. Quote Link to comment https://forums.phpfreaks.com/topic/269754-using-old-scripts-on-php5/#findComment-1387122 Share on other sites More sharing options...
Solution PFMaBiSmAd Posted October 23, 2012 Solution Share Posted October 23, 2012 (edited) Here's the likely php change that caused the preexisting error in your code to stop returning any data (in my test above, mysql_result returned a null value when using code with the incorrect '$roomnumber' 2nd parameter) - The newer internal parameter parsing API has been applied across all the extensions bundled with PHP 5.3.x. This parameter parsing API causes functions to return NULL when passed incompatible parameters. Edited October 23, 2012 by PFMaBiSmAd Quote Link to comment https://forums.phpfreaks.com/topic/269754-using-old-scripts-on-php5/#findComment-1387124 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.