I have a MySQL database and I'm able to access it correctly. I am also
able to execute select, update and insert queries, however I am getting
warnings saying:
"supplied argument is not a valid MySQL result resource" and the result
set returned is empty (for queries other than select).
Strangely, my die function includes the query but the query is not
printed. I've however printed the queries before executing and they are
fine too. Can anyone discover the problem? The code is as below:
(please also note that as the code below has @'s the warnings are not
displayed)
if(($_POST['ADD'] == "1") || ($_POST['ADD'] == "0")) {
session_start() ;
$cart_id = GetCartId(); // my own function, works fine
$merchants = explode("_", $_GET['merchants']);
$merchant_id = $merchants[(int)$_POST['merchantid']];
$connection = db_connect(); // my own function, works fine
if($connection) {
$where_clause = " WHERE `Session`= '" . $cart_id . "' AND `Product ID`
= " . $_POST['productid'];
$cart_query = "SELECT * from `Shopping`" . $where_clause;
$cart_result = @mysql_query($c art_query, $connection) or
die(mysql_error () . ": $cart_query");
$cart_row = @mysql_fetch_ar ray($cart_resul t);
$result = null;
if($_POST['ADD']=="1") {
if($cart_row) {
$update_query = "UPDATE `Shopping` SET `Merchant ID` = " .
$merchant_id . " , `quantity`= " . $_POST['quantity'] .
$where_clause;
echo $update_query;
$update_result = @mysql_query($u pdate_query, $connection) or
die(mysql_error () . ": $update_query") ;
/* Error comes here */
if(($result = @mysql_fetch_ar ray($update_res ult)))
{}
} else {
$add_query = "INSERT INTO `Shopping` ( `Session`, `Product ID`,
`Merchant ID`, `quantity` ) VALUES ( '" . $cart_id . "', "
..$_POST['productid'] . ", " . $merchant_id . ", " . $_POST['quantity']
.. ")";
$add_result = @mysql_query($a dd_query, $connection) or die
(mysql_error() . ": $add_query");
/* Error comes here */
if(($result = @mysql_fetch_ar ray($add_result )))
{}
}
} else {
//delete
$delete_query = "DELETE FROM `Shopping` " . $where_clause;
$delete_result = @mysql_query($d elete_query, $connection) or die
(mysql_error() . ": $delete_query") ;
if(($result=@my sql_fetch_array ($delete_result )))
{}
}
} //if connection
} // if $_POST['ADD']
able to execute select, update and insert queries, however I am getting
warnings saying:
"supplied argument is not a valid MySQL result resource" and the result
set returned is empty (for queries other than select).
Strangely, my die function includes the query but the query is not
printed. I've however printed the queries before executing and they are
fine too. Can anyone discover the problem? The code is as below:
(please also note that as the code below has @'s the warnings are not
displayed)
if(($_POST['ADD'] == "1") || ($_POST['ADD'] == "0")) {
session_start() ;
$cart_id = GetCartId(); // my own function, works fine
$merchants = explode("_", $_GET['merchants']);
$merchant_id = $merchants[(int)$_POST['merchantid']];
$connection = db_connect(); // my own function, works fine
if($connection) {
$where_clause = " WHERE `Session`= '" . $cart_id . "' AND `Product ID`
= " . $_POST['productid'];
$cart_query = "SELECT * from `Shopping`" . $where_clause;
$cart_result = @mysql_query($c art_query, $connection) or
die(mysql_error () . ": $cart_query");
$cart_row = @mysql_fetch_ar ray($cart_resul t);
$result = null;
if($_POST['ADD']=="1") {
if($cart_row) {
$update_query = "UPDATE `Shopping` SET `Merchant ID` = " .
$merchant_id . " , `quantity`= " . $_POST['quantity'] .
$where_clause;
echo $update_query;
$update_result = @mysql_query($u pdate_query, $connection) or
die(mysql_error () . ": $update_query") ;
/* Error comes here */
if(($result = @mysql_fetch_ar ray($update_res ult)))
{}
} else {
$add_query = "INSERT INTO `Shopping` ( `Session`, `Product ID`,
`Merchant ID`, `quantity` ) VALUES ( '" . $cart_id . "', "
..$_POST['productid'] . ", " . $merchant_id . ", " . $_POST['quantity']
.. ")";
$add_result = @mysql_query($a dd_query, $connection) or die
(mysql_error() . ": $add_query");
/* Error comes here */
if(($result = @mysql_fetch_ar ray($add_result )))
{}
}
} else {
//delete
$delete_query = "DELETE FROM `Shopping` " . $where_clause;
$delete_result = @mysql_query($d elete_query, $connection) or die
(mysql_error() . ": $delete_query") ;
if(($result=@my sql_fetch_array ($delete_result )))
{}
}
} //if connection
} // if $_POST['ADD']
Comment