Page 2 of 2
Posted: Thu Dec 15, 2005 5:44 pm
by RobertGonzalez
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:
Code: Select all
$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.
Posted: Thu Dec 15, 2005 5:52 pm
by RobertGonzalez
Or another thing you can try is changing your PHP code. Try this out in place of what you originally posted and see if it works.
Code: Select all
//New Shipping
function MXKRate_newshipping($oldCost){
global $HTTP_GET_VARS,$HTTP_POST_VARS,$HTTP_SESSION_VARS;
$KartFV_RS = getKartRecordset();
$total = $KartFV_RS->getTotalPrice(true);
// connect to MySQL
mysql_connect("xxxx", "xxxx", "xxxx")
or die ("Unable to connect to database.");
// select database on MySQL server
mysql_select_db("clarik_mxshop")
or die ("Unable to select database.");
// formulate query
$sqlwhere = $HTTP_SESSION_VARS['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());
}
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;
}
//End New Shipping
Posted: Thu Dec 15, 2005 5:58 pm
by AKA Panama Jack
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.

Posted: Thu Dec 15, 2005 6:01 pm
by AKA Panama Jack
The other thing he should do is STOP using these variables...
Code: Select all
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.
Posted: Thu Dec 15, 2005 6:12 pm
by RobertGonzalez
I agree with you on these variations of the superglobal array. But his session data is being passed. He tested for that already.
Posted: Thu Dec 15, 2005 6:25 pm
by RobertGonzalez
Alladinsane, here is a little cleaner coded function for you, ala some suggestions from AKA Panama Jack:
Code: Select all
//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
Posted: Thu Dec 15, 2005 8:04 pm
by AKA Panama Jack
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.
Posted: Fri Dec 16, 2005 12:30 am
by AGISB
I assume you recompiled PHP as well. If you did not PHP does still want to work with the old version that might be overwritten or not running.