-1

I have a problem with sending data to a table, the table is supposed to keep all placed order, cart_array, name, first name, last name, etc..

It submits, first time, and then if I want to place another order nothing happens... it won't send the data to the table.

If i delete the first entry from the table and place the order again, it works but the Auto Increment ID jumps from the one I just deleted(let's say from id-1 to id-14, depends on mow many attempts i've had)

the php block is

<?php

function register_transaction($register_order){
    array_walk($register_order, 'array_sanitize');

    $fields = '`' . implode('`, `', array_keys($register_order)) . '`';
    $data = '\'' . implode('\', \'', $register_order) . '\'';

    mysql_query("INSERT INTO `transactions` ($fields) VALUES ($data)"); 
}

if (empty($_POST) === false) {
            $register_order = array(
            'product_id_array' => $_POST['product_id_array'],
            'payer_email' => $_POST['payer_email'],
            'first_name' => $_POST['first_name']
                        );          
            register_transaction($register_order); 

        }
?>

form

<form action="" method="post">
    <ul style="position:relative">

        <li style="float:none;">Cart<br />
        <input type="text" name="product_id_array" value="<?php echo $product_id_array;?>" /></li>

        <li style="float:none;">Email<br />
        <input type="email" name="payer_email" value="<?php echo $user_data["email"];?>" /></li>

        <li style="float:none;">Name<br />
        <input type="text" name="first_name" value="<?php echo $user_data["name"];?>" /></li>

        <li style="float:none;">
        <input type="submit" value="Trimite Comanda" /></li>
    </ul>
</form> 
I'm Geeker
  • 4,601
  • 5
  • 22
  • 41
  • Add [error reporting](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php/845025#845025) to the top of your file(s) _while testing_ right after your opening PHP tag for example ` – RiggsFolly Jun 29 '16 at 09:47
  • @RiggsFolly It only gives me "Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future:" and I'm aware about this, still I don't think this is the problem because it works once, and the entire website works , registering users, adding products, creating cart array.. – Ciprian Kis Jun 29 '16 at 09:56
  • @RiggsFolly the only Unique field in the Table is ID that is Auto Increment.. so it shouldn't be a problem. – Ciprian Kis Jun 29 '16 at 09:58

1 Answers1

1

Fixed... there was another unique field in the Database Table.. I wasn't sending any data to it and it remained blank after the first submit, and because it was unique, it couldn't be blank again..