PHP strange error with MY_SQL database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • asra_baig@rocketmail.com

    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($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']

  • Pedro Graca

    #2
    Re: PHP strange error with MY_SQL database

    asra_baig@rocke tmail.com wrote:[color=blue]
    > 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)[/color]


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

    <snip>
    [color=blue]
    > $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)))[/color]

    <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.





    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!

    Comment

    • Dani CS

      #3
      Re: PHP strange error with MY_SQL database

      asra_baig@rocke tmail.com wrote:[color=blue]
      > 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)
      >[/color]

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

      <snip>

      Comment

      Working...