Page 1 of 1

Error in code after php4 to php5 upgrade

Posted: Tue Jul 22, 2008 9:00 pm
by psanders
I created a stock reordering system for our site that works a treat. We sell about 1200 items a month from multiple suppliers and ordering was a nightmare prior to the program. I have been packaging it up as a oscommerce contrib but have a snag with one of the modules under php5. It craps out with the blurb \\\\\\\\\\\\\\\'supplied argument not a valid mysql result resource\\\\\\\\\\\\\\\'. I think it is due to the way I\\\\\\\\\\\\\\\'m using the array?

Works fine on php4.. Any ideas welcome...

This is a snippet of the offending bit of code. $text is the order number to start from.


$conn = mysql_connect($server, $user, $password);
mysql_select_db($database, $conn) or die (mysql_error());

$sql = \\\"select `*` from `orders_products` where `orders_id` >= $text\\\";
$index = mysql_query($sql, $conn);
$rawdata = array();

$i = \\\"0\\\";

while ($array = mysql_fetch_array($index)) { // <---- craps out here on php5 - works fine on php4----> //

$sql = \\\"select `*` from `products` where `products_id` = $array[products_id]\\\";
$records = mysql_query($sql, $conn);

while ($result = mysql_fetch_array($records)) {

if ($array[products_id] == $result[products_id]) {

$rawdata[$i][0] = $result[products_model];

}

}

$rawdata[$i][1] = $array[products_name];
$rawdata[$i][2] = $array[products_quantity];

$sql = \\\"select `*` from `orders` where `orders_id` = $array[orders_id]\\\";
$records = mysql_query($sql, $conn);

while ($result = mysql_fetch_array($records)) {

if ($result[orders_status] != \\\"3\\\") {

$rawdata[$i][3] = \\\"Order \\\" . $result[orders_id];

} else {

$rawdata[$i][3] = \\\"Stock\\\";

}

}

$i++;

}


?>

Re: Error in code after php4 to php5 upgrade

Posted: Tue Jul 22, 2008 9:23 pm
by EverLearning
Put

Code: Select all

$index = mysql_query($sql, $conn) or die(mysql_error());
since your error message is saying that the $index is not a valid mysql result resource, so we can see whats wrong.

Also use[ code=php ][ /code ] tags (without spaces) when posting your code, as it makes it much easier for people to read your code.

And whats with all the extra '\\\'?

Re: Error in code after php4 to php5 upgrade

Posted: Thu Jul 24, 2008 12:45 am
by psanders
Thanks everlearning, I\'ll try it tonight... All the \\\\\\ seem to be an artifact of cut and paste into the pbpBB where there are quotes??

Ta.

Re: Error in code after php4 to php5 upgrade

Posted: Sun Aug 24, 2008 8:05 am
by psanders
now it says...

unknown column '*' in 'field list'

Is this a magic quotes thing? I tried changing all the magic quote stuff to =on in php.ini but it did not seem to make any difference?

Regards,

Paul.

Re: Error in code after php4 to php5 upgrade

Posted: Fri Aug 29, 2008 9:28 pm
by EverLearning
Sorry for not replying sooner. I've been away. Remove the backticks(`) from * sign, or better yet, list the columns you want returned in the SELECT statement.

Re: Error in code after php4 to php5 upgrade

Posted: Mon Oct 20, 2008 7:11 am
by psanders
Finally got around to looking at the bit of code again.

Basically select * is bad practice and it seems to be enforced by phpV.
I enumerated all the required tables in the select statements and it all worked again :)

Thank you for your input and suggestions

Paul.