Jump to content

Using Old Scripts On Php5


talmik
Go to solution Solved by PFMaBiSmAd,

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
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by PFMaBiSmAd
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Solution

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 by PFMaBiSmAd
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.