Jump to content

Using Old Scripts On Php5


talmik

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/269754-using-old-scripts-on-php5/
Share on other sites

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).

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

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.

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?

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.