PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
He is returning zero results. It has something to do with the script passing a value from the session that is not matching what is in the database. So the script has it, but the database can't find it so the result set is empty.
What he needs help with is finding out why eventhough the session var is getting captured and set, when it is passed to the script's SQL statement it is not fetching the record requested.
That leads me to an idea. Alladinsane, modify your script a little by doing this:
$sqlwhere = $HTTP_SESSION_VARS['KT_kartOrderId'];
$sql = "SELECT state_ord FROM order_ord WHERE id_ord = '$sqlwhere'";
// Added for testing
echo "This is my SQL statement: $sql<br />";
This will show the exact query that is being sent to MySQL. Then run that same query in phpMyAdmin and see if the results are the same or different.
Everah wrote:He is returning zero results. It has something to do with the script passing a value from the session that is not matching what is in the database. So the script has it, but the database can't find it so the result set is empty.
But he really should be error trapping for 0 results. It's lax programming to assume that there will always be a record. Makes a web site look amaturish if an error like that crops up.
global $HTTP_GET_VARS,$HTTP_POST_VARS,$HTTP_SESSION_VARS;
And change to using $_GET, $_POST and $_SESSION. If his server every upgrades to PHP 5 then those variables are disabled by default. If his server also upgraded to PHP 5 when it upgraded to Mysql 4.1 then that might be his problem with session data not being stored.
//New Shipping
function MXKRate_newshipping($oldCost) {
global $_GET, $_POST, $_SESSION;
$KartFV_RS = new getKartRecordset();
$total = $KartFV_RS->getTotalPrice(true);
// connect to MySQL
if (!mysql_connect("xxxx", "xxxx", "xxxx")) {
die ("Unable to connect to database: " . mysql_error());
}
// select database on MySQL server
if (!mysql_select_db("clarik_mxshop")) {
die ("Unable to select database: " . mysql_error());
}
// formulate query
/*
* Just a tip, you might want to validate this var before sending it SQL
*
*/
$sqlwhere = $_SESSION['KT_kartOrderId'];
$sql = "SELECT state_ord FROM order_ord WHERE id_ord = '$sqlwhere'";
//Test SQL
echo "My query is: $sql<br />";
if (!$result_temp = mysql_query($sql)) {
die("Could not query the database: " .mysql_error());
}
if (mysql_num_rows($result_temp) == 1) {
while ($row = mysql_fetch_array($result_temp)) {
$result = $row['state_ord'];
}
//Testing
echo "My result is $result<br />";
// close database connection
mysql_close();
if ($result == "UK Mainland" && $total<50) {return 7.05;}
else if ($result == "UK Mainland" && $total<100 && $total>50 ) {return 3.53;}
else if ($result == "UK Mainland" && $total>100) {return 0;}
else if ($result == "Channel Isles" && $total<400) {return 29.38;}
else if ($result == "Channel Isles" && $total>400) {return 0;}
else if ($result == "Isle of Man" && $total<300) {return 17.63;}
else if ($result == "Isle of Man" && $total>300) {return 0;}
else if ($result == "Isle of Wight" && $total<300) {return 17.63;}
else if ($result == "Isle of Wight" && $total>300) {return 0;}
else if ($result == "Northern Ireland" && $total<300) {return 17.63;}
else if ($result == "Northern Ireland" && $total>300) {return 0;}
else if ($result == "Scilly Isles" && $total<300) {return 17.63;}
else if ($result == "Scilly Isles" && $total>300) {return 0;}
else if ($result == "Republic of Ireland" && $total<300) {return 23.50;}
else if ($result == "Republic of Ireland" && $total>300) {return 0;}
else return 0;
} else {
// Either zero records or too many records
return false;
}
}
//End New Shipping
I wonder if they also upgraded other things like Apache at the same time. I upgraded to Apache 2.2.0 on my work server and the new version uses a different user name by default and I found out that caused my sessions to stop working because the session directory didn't match the group or user that was being used by the upgraded Apache. PHP will use the user and group from apache for it's permissions. I just had to change the user for apache to what I was using before I upgraded and sessions started working again.
If something like that happened then there isn't much he can do about it if he could even find out if that was the problem, other than ask the hosting company to fix the server.