473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

PHP strange error with MY_SQL database

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($cart_query, $connection) or
die(mysql_error() . ": $cart_query");
$cart_row = @mysql_fetch_array($cart_result);

$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($update_query, $connection) or
die(mysql_error() . ": $update_query");
/* Error comes here */
if(($result = @mysql_fetch_array($update_result)))
{}

} 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($add_query, $connection) or die
(mysql_error() . ": $add_query");
/* Error comes here */
if(($result = @mysql_fetch_array($add_result)))
{}
}
} else {
//delete
$delete_query = "DELETE FROM `Shopping` " . $where_clause;
$delete_result = @mysql_query($delete_query, $connection) or die
(mysql_error() . ": $delete_query");
if(($result=@mysql_fetch_array($delete_result)))
{}
}

} //if connection
} // if $_POST['ADD']

Jul 17 '05 #1
2 1593
as*******@rocketmail.com wrote:
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)

UGH! UUUGGHHHHH!!!!!!! OUCH!!!
Please, indent your code before pasting it to the newsgroups.

<snip>
$update_query = "UPDATE `Shopping` SET `Merchant ID` = " .
$merchant_id . " , `quantity`= " . $_POST['quantity'] .
$where_clause;
echo $update_query;
$update_result = @mysql_query($update_query, $connection) or
die(mysql_error() . ": $update_query");
/* Error comes here */
if(($result = @mysql_fetch_array($update_result)))


<snip>

OUCH!!!!!!!! MY EYES HURT!!!!!!!!!!
Please, indent your code before pasting it to the newsgroups.
mysql_fetch_*() functions are only valid after a mysql_query() for
SELECT, SHOW, EXPLAIN or DESCRIBE.

for UPDATE, INSERT, DELETE, ... the mysql_query() is all you need.

*Read* the mysql_query() manual page.
http://www.php.net/mysql_query


Please, indent your code before pasting it to the newsgroups.

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jul 17 '05 #2
as*******@rocketmail.com wrote:
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)


Remove the @'s and correct the errors that you will get.

<snip>
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: inonzuk | last post by:
why strange you ask? here goes: I have been working with Php and Mysql for a week without any problems. Today I tried executing a php page that connects to mysql and creates a new database, I...
25
by: Neil Ginsberg | last post by:
I have a strange situation with my Access 2000 database. I have code in the database which has worked fine for years, and now all of a sudden doesn't work fine on one or two of my client's...
1
by: intl04 | last post by:
I am getting strange print-related error messages when trying to create (not print!) reports. For example, when I click 'new' to create a report then choose 'design view', I get an error message...
6
by: Gary | last post by:
I have an application that has been working just fine for a couple of years. It queries a SQL database and returns some formatted data back to the client. I have a new client, who has a larger...
2
by: Buddy Ackerman | last post by:
I have a web app that I have setup on numerous web servers. I've set one up for a new client at their hosting facility and cannot get it to connect to their database. I get a "SQL Server does not...
4
by: Praveen_db2 | last post by:
Hi All I am getting strange errors in my db2diag.log can any one tell me what these errors mean?? Following is the code from my db2diag.log...
0
by: ivb | last post by:
Hi all, I am using DB2 8.1.11.1 on NT with ASP.NET 1.1 When application make connection to database (via ADO.NET), it set "Connection timeout" parameter to 30 seconds. After, when my webpage...
5
by: Ian | last post by:
Hi everyone, I have found some bizarre (to me...!) behaviour of the Form_Activate function. I have a form which has a button control used to close the form and a subform with a datasheet view...
2
by: sonasiva | last post by:
iam getting the error as follows Error Type: Microsoft JET Database Engine (0x80040E14) Syntax error in FROM clause following is the showing error my_sql="SELECT company_name, FROM data as...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.