简体   繁体   中英

Add multiple products to cart in php

I need some help, how to add multiple products? will I add a code or change some? help please. thank u for response.

if (isset($_POST['submit'])) {
    $connect = mysqli_connect("localhost", "root", "", "tut");
    $test= $values['item_name'];
    $test3 = $values["item_quantity"];
    $test2= $values["product_price"];
    $query = "INSERT INTO orders (Quantity,PriceDetails,OrderTotal) VALUES ('$test3','$test','$total')";
    $res = mysqli_query($connect, $query);
}

Just try to inspire yourself with the code below. Also try to safe your data with simple add-on:

$test = mysql_real_escape_string($values['item_name']);

You may come alright:

function db_action($data = array()) {
    switch ($data['action']) {
        case 'insert':
            $keys = array(); $values = array();

            foreach ($data['data'] as $key => $value) {
                $keys[$key] = $key;
                $values[$key] = "'".$value."'";
            }

            $keys = implode(', ', $keys);
            $values = implode(', ', $values);
            mysql_query("INSERT INTO ".$data['table']." (".$keys.") VALUES (".$values.")");
            break;
        case 'update':
            mysql_query("UPDATE ".$data['table']." SET ".$values." WHERE ".$key." = ".$id);
            break;
        case 'delete':
            mysql_query("DELETE FROM ".$data['table']." WHERE ".$key." = ".$id);
            break;
    }

    return;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM