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++;
}
?>
Error in code after php4 to php5 upgrade
Moderator: General Moderators
- EverLearning
- Forum Contributor
- Posts: 282
- Joined: Sat Feb 23, 2008 3:49 am
- Location: Niš, Serbia
Re: Error in code after php4 to php5 upgrade
Put
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 '\\\'?
Code: Select all
$index = mysql_query($sql, $conn) or die(mysql_error());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
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.
Ta.
Re: Error in code after php4 to php5 upgrade
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.
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.
- EverLearning
- Forum Contributor
- Posts: 282
- Joined: Sat Feb 23, 2008 3:49 am
- Location: Niš, Serbia
Re: Error in code after php4 to php5 upgrade
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
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.
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.