PDA

View Full Version : Need php5 expert


kylek
07-09-2015, 07:23 PM
I have an addon product that worked in php4 but we upgraded to php5 and most of it works except for 1 error showing at top of page. I have no knowledge of php but am trying to learn.

This is the error we are getting:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/xxxx/xxx/pickem/includes/header.php on line 122This is line 122 header.php:

if (mysql_num_rows($query)) {Using http://phpcodechecker.com/ I checked line 119 to line 129:

$sql = "select * from " . $db_prefix . "users where userID = " . $user->userID;
$query = mysql_query($sql);

if (mysql_num_rows($query)) {
$result = mysql_fetch_array($query);
$template_name = $result['template_name'];
}

if (!empty($_POST['template_name'])) $template_name = $_POST['template_name'];

?>Results:
Warning: There are 3 functions in your code that have been deprecated in the current version of PHP :
mysql_fetch_array()
mysql_num_rows()
mysql_query()

Any ideas on what may work?

kh99
07-09-2015, 07:31 PM
I'm not a php5 expert. But, I see that mysql_query() can return FALSE in the case of an error, and since the error message says that $query is a boolean, I'd assume that's what's happening. You could just check for that in the 'if', like maybe:
if ($query !== FALSE && mysql_num_rows($query)) {

but I don't know what the error would be or what you would want to do in that case, so that may or may not be the way to handle it.

The mysql interface has been deprecated so you should change to one of the other interfaces, but you can ignore that for now.

ETA: Actually, if that plugin is depending on the database connection that vbulletin opens, and you've changed to using mysqli in the config.php, then the error could be that there's no database connection. In that case what you probably want to do is rewrite the plugin to use the vbulletin database functions (which isn't as difficult as it may sound since the functions are named mostly the same as the mysql functions). That will also take care of the deprecated interface issue.

kylek
07-09-2015, 07:57 PM
Thank you very much kh99!!

I changed it to what you suggested and the error is gone now.