Jump to content

Using Old Scripts On Php5


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
https://forums.phpfreaks.com/topic/269754-using-old-scripts-on-php5/
Share on other sites

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 by Pikachu2000

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

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?

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?

Edited by PFMaBiSmAd

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.

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