Ich habe ein kleines Problem mit Daten aus einer Tabelle mit While-Schleife. Was ich tun möchte, ist einfach Ich möchte alle Daten von table cart
mit Cookie-Wert von table orders
, die einen Cookie-Wert und Abfrage Tabellen Warenkorb, um Daten, die den Cookie-Wert in der Warenkorb-Tabelle entspricht und nehmen sie in table orders_final
. Jetzt ist dies . Jetzt ist der letzte Teil, nachdem er mit Cookie-Wert Wagen Tabelle Abfrage aus, um Tisch bekommen, ich will jetzt mit allen Daten in orders_final Tabelle platzieren, dass die Cookie-Wert aus, um Spiele und Warenkorb Holen Sie Daten aus der Tabelle und Einfügen in eine andere Tabelle aus While-Schleife
$zomo = $_COOKIE['shopa']; // this is the cookie that is stored in the cart table and updated when the transaction is successful
$get_products = "SELECT * FROM `cart` WHERE cookie_value = '$zomo'";
$limo = mysqli_query($con, $get_products);
while($colo = mysqli_fetch_array($limo)){
$product_id = $colo['product_id'];
$order_quantity = $colo['order_quantity'];
$cookie_value = $colo['cookie_value'];
//var $dance is when i update the table with data after payment and data gotten from my payment processing company
$dance = "UPDATE `orders` SET `status`='$r_status',`time`='$r_time',`date`='$r_date',`reference`='$r_reference',`transaction_status`='$r_transaction_status',`transaction_method`='$r_transaction_method',`final_price`='$r_final_price',`order_id`='$r_order_id',`currency`='$r_currency',`referrer`='$r_referrer' WHERE cookie_bought = '$zomo'";
$uii = mysqli_query($con, $dance);
if ($uii){
//this variable insert is where i want to insert all data gotten from cart table above and insert into orders_final, where order table holds the cookie value which was created during shopping which is cookie name shopa held in the variable zomo
$insert = "INSERT INTO `orders_final`(`product_id`, `cookie_value`, `trx_id`, `order_quantities`) VALUES ('$product_id','$zomo','$r_reference','$order_quantity')";
$bena = mysqli_query($con, $insert);
if ($bena){
$delc = "DELETE FROM `cart` WHERE cookie_value = '$zomo'";
$tipee = mysqli_query($con, $delc);
if ($tipee){
perform_success();
}
}
}
}
Sie wahrscheinlich vermeiden können zwei Abfragen und eine Schleife mit, indem stattdessen eine 'INSERT INTO..SELECT' Abfrage zu tun. Eine sinnvolle Formatierung des Codes (richtiges Einrücken) würde auch das Lesen erleichtern. – Qirel
Sie wollen was ??? –
Sie verwenden bereits eine API, die ** vorbereitete Anweisungen ** mit beschränkter Variableneingabe unterstützt. Sie sollten parametrisierte Abfragen mit Platzhaltern (vorbereitete Anweisungen) verwenden, um Ihre Datenbank gegen [SQL-injection] (http://stackoverflow.com) zu schützen/q/60174 /)! Beginnen Sie mit [mysqli :: prepare() '] (http://php.net/mysqli.prepare) und [mysqli_stmt :: bind_param()'] (http://php.net/mysqli-stmt .bind-param). – Qirel