Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP form data to multiple MySQL entries
    primarykey
    data
    text
    <p>Hi all i'm trying to change the code bellow to show that if the customer selects multiple products in the form, will create a different MySQL query for each product selected.</p> <p>Pretty sure I need some kind of for each loop to make it work but have no idea.</p> <p>Any help would be greatly appreciated!</p> <p>Form Code:</p> <pre><code>&lt;input type="checkbox" name="TG01" value="TG01"&gt;China Travel Guide - $45.00&lt;br/&gt; &lt;input type="checkbox" name="TG01" value="TG02"&gt;Berlin Travel Guide - $45.00&lt;br/&gt; &lt;input type="checkbox" name="TG03" value="TG03"&gt;France Travel Guide - $45.00&lt;br/&gt; &lt;input type="checkbox" name="TG04" value="TG04"&gt;Thailand Travel Guide - $45.00&lt;br/&gt; </code></pre> <p>PHP Code:</p> <pre><code>&lt;?php include("config.php"); $con=mysqli_connect("host","user","pass","somedb"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $qtychina = $_POST["china_travel_guide"]; $qtyberlin = $_POST['berlin_travel_guide']; $qtyfrance = $_POST['france_travel_guide']; $qtythailand = $_POST['thailand_travel_guide']; $china = $_POST["TG01"]; $berlin = $_POST['TG02']; $france = $_POST['TG03']; $thailand = $_POST['TG04']; $sql="INSERT INTO ORDER_TBL (TRANSACTION_ID, CUSTOMER_ID, PRODUCT_ID, QUANTITY) VALUES ('','$_SESSION[user]','$china','$qtychina')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); exit; } echo "Congratulations your order has been processed!"; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload