1

I have a site www.jazz.eu. I did an exact copy of this site to another with a different domain name, in a different server. The new one is www.vetur.nl.

Everything works fine (I mean similar to jazz.eu). Except the cart process. First when I see the cart I always have a line with an empty product. I can't remove it. see what i mean

http://www.vetur.nl/cart_empty_product_line.jpg

and the next problem that i have is that when I try to refresh the cart or send the order I get this message

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
'sender_full_name='',sender_afm='',sender_doy='',sender_work='',sender_person='',' at line 1
query=update basket set selected_quantity=,sender_full_name='' ,sender_afm='',sender_doy='',sender_work='',sender_person='',sender_address='',sender_zip='',sender_tel='',sender_fax='', addresser_email='', additional='' where session_id = 'ihcvafpk3fgqh6jra1mrplgkr1' and id= 

I think the problem is in this file process.php but I can't find it. The exact file works fine in my first site jazz.eu. The code of process.php that seems that have problem is below. Thank you and forgive any mistake in posting. It is the first time I post here.

    function procMy_cart(){
        global $session, $form,$database,$mailer;

        $session_id = session_id();
        if ((isset($_POST['order'])) && ($_POST['order']==1)) {
            if (!eregi("[a-z\α-ω\!\"\£\$\%\^\&\*\(\)\-\+\{\}\:\;\'\@\~\#\\\|\<\>\?\/]", $_POST['update_quantity'][$i])) {
                        For ($i=0;$i<count($_POST['update_quantity']);$i++) {

                    if (!eregi("[a-z\α-ω\!\"\£\$\%\^\&\*\(\)\-\+\{\}\:\;\'\@\~\#\\\|\<\>\?\/]", $_POST['update_quantity'][$i])) {
                        //$update_db="update basket set selected_quantity=".$_POST['update_quantity'][$i].",addresser='".$_POST['addresser']."',addresser_tel='".$_POST['addresser_tel']."', addresser_email='".$_POST['addresser_email']."', additional='".$_POST['additional']."' where session_id = '$session_id' and id=".$_POST['update_id'][$i]."";
                        $update_db="update basket set selected_quantity=".$_POST['update_quantity'][$i].",sender_full_name='".$_POST['addresser']."',sender_afm='".$_POST['addresser_afm']."',sender_doy='".$_POST['addresser_doy']."',sender_work='".$_POST['addresser_work']."',sender_person='".$_POST['addresser_contact']."',sender_address='".$_POST['addresser_address']."',sender_zip='".$_POST['addresser_zip']."',sender_tel='".$_POST['addresser_tel']."',sender_fax='".$_POST['addresser_fax']."', addresser_email='".$_POST['addresser_email']."', additional='".$_POST['additional']."' where session_id = '$session_id' and id=".$_POST['update_id'][$i]."";
                        $result=$database->query($update_db);

                    } else {

                        //$update_db="update basket set selected_quantity=1,addresser='".$_POST['addresser']."',addresser_tel='".$_POST['addresser_tel']."',addresser_email='".$_POST['addresser_email']."', additional='".$_POST['additional']."' where session_id = '$session_id' and id=".$_POST['update_id'][$i]."";
                        $update_db="update basket set selected_quantity=1,sender_full_name='".$_POST['addresser']."',sender_afm='".$_POST['addresser_afm']."',sender_doy='".$_POST['addresser_doy']."',sender_work='".$_POST['addresser_work']."',sender_person='".$_POST['addresser_contact']."',sender_address='".$_POST['addresser_address']."',sender_zip='".$_POST['addresser_zip']."',sender_tel='".$_POST['addresser_tel']."',sender_fax='".$_POST['addresser_fax']."', addresser_email='".$_POST['addresser_email']."', additional='".$_POST['additional']."' where session_id = '$session_id' and id=".$_POST['update_id'][$i]."";
                        $result=$database->query($update_db);
                    }
                }
            }
//          $retval = $session->my_cart($_POST['addresser'], $_POST['addresser_doy'], $_POST['addresser_work'], $_POST['addresser_afm'], $_POST['addresser_address'], $_POST['addresser_zip'], $_POST['addresser_contact'], $_POST['addresser_email'], $_POST['addresser_tel'], $_POST['addresser_fax'], $_POST['additional']);
//          if ($retval) {
//               $_SESSION['send_order'] = true;
//              header("Location: my_cart2.php");//.$session->referrer);
//          } else {
//              $_SESSION['value_array'] = $_POST;
//              $_SESSION['error_array'] = $form->getErrorArray();
//              header("Location: my_cart2.php");//.$session->referrer);
//          }
        header("Location: order2.php");

        } else if ((isset($_POST['order'])) && ($_POST['order']!=1)) {
            if ((isset($_POST['refresh_basket'])) && ($_POST['refresh_basket']==1)) {
                For ($i=0;$i<count($_POST['update_quantity']);$i++) {
                    //echo $_POST['update_id'][$i];
                    if (!eregi("[a-z\α-ω\!\"\£\$\%\^\&\*\(\)\-\+\{\}\:\;\'\@\~\#\\\|\<\>\?\/]", $_POST['update_quantity'][$i])) {
                        //$update_db="update basket set selected_quantity=".$_POST['update_quantity'][$i].", addresser='".$_POST['addresser']."', addresser_tel='".$_POST['addresser_tel']."',  addresser_email='".$_POST['addresser_email']."', additional='".$_POST['additional']."' where session_id = '$session_id' and id=".$_POST['update_id'][$i]."";
                        $update_db="update basket set selected_quantity=".$_POST['update_quantity'][$i].",sender_full_name='".$_POST['addresser']."',sender_afm='".$_POST['addresser_afm']."',sender_doy='".$_POST['addresser_doy']."',sender_work='".$_POST['addresser_work']."',sender_person='".$_POST['addresser_contact']."',sender_address='".$_POST['addresser_address']."',sender_zip='".$_POST['addresser_zip']."',sender_tel='".$_POST['addresser_tel']."',sender_fax='".$_POST['addresser_fax']."', addresser_email='".$_POST['addresser_email']."', additional='".$_POST['additional']."' where session_id = '$session_id' and id=".$_POST['update_id'][$i]."";
                        $result=$database->query($update_db);

                    } else {
                        //$update_db="update basket set selected_quantity=1, addresser='".$_POST['addresser']."', addresser_tel='".$_POST['addresser_tel']."',  addresser_email='".$_POST['addresser_email']."', additional='".$_POST['additional']."' where session_id = '$session_id' and id=".$_POST['update_id'][$i]."";
                        $update_db="update basket set selected_quantity=1,sender_full_name='".$_POST['addresser']."',sender_afm='".$_POST['addresser_afm']."',sender_doy='".$_POST['addresser_doy']."',sender_work='".$_POST['addresser_work']."',sender_person='".$_POST['addresser_contact']."',sender_address='".$_POST['addresser_address']."',sender_zip='".$_POST['addresser_zip']."',sender_tel='".$_POST['addresser_tel']."',sender_fax='".$_POST['addresser_fax']."', addresser_email='".$_POST['addresser_email']."', additional='".$_POST['additional']."' where session_id = '$session_id' and id=".$_POST['update_id'][$i]."";
                        $result=$database->query($update_db);
                    }
                }
            }
            $_SESSION['value_array'] = $_POST;
            $_SESSION['error_array'] = $form->getErrorArray();
            header("Location: my_cart2.php");//.$session->referrer);
        }
    } // end cart
  • 1
    I'd have thought `set selected_quantity=,` would seem less than entirely ideal. Also, unless your database class is doing something *really* clever, you need to read "[How can I prevent SQL injection in PHP?](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)" as a priority. – John Parker Aug 09 '13 at 17:13
  • nooooooo `eregi`!! As of PHP 5.3.0, the `regex` extension is deprecated in favor of the [PCRE extension](http://www.php.net/manual/en/book.pcre.php). Calling this function will issue an E_DEPRECATED notice. – bansi Aug 09 '13 at 17:15

1 Answers1

0

The variable $_POST['update_quantity'][$i] doesn't have a value. If you look at the query you'll notice set selected_quantity=,sender_full_name=''. You need at least a set of single quotes or null assigned to selected_quantity.

You should never assign _POST data directly into a query. Always scrub it somehow to avoid SQL Injection attacks. You shold probably assign $_POST['update_quantity'][$i] to a variable early on and perform some logic to ensure it has a valid value and if not, either prevent the query from running or add a default value.

Robbert
  • 6,481
  • 5
  • 35
  • 61