How insert multiple rows in mysql table with php array? [duplicate] - php

This question already has answers here:
Best way to INSERT many values in mysqli?
(4 answers)
Closed 2 years ago.
I need to insert entries to mysql table from the form below.
1-form contains many rows.
2-entry will not be always consecutive in the rows (meaning row 1 can be empty and next row not)
3-all rows containing entries should be saved in the db table.
i want to INSERT INTO oz2ts_custompc_details (part_id, quantity, price)
Here is my entry form (custompc_form2.php)
<!DOCTYPE html>
<html>
<body>
<form action="../subs/custompcorder2.php/" method="post" id="form">
<p><input id="name" name="part_id[]"/>
<input type="text" id="quantity" name="quantity[]"/>
<input id="name-data" type="text" name="price[]"/></p>
<p><input id="name" name="part_id[]"/>
<input type="text" id="quantity" name="quantity[]"/>
<input id="name-data" type="text" name="price[]"/></p>
<p><input id="name" name="part_id[]"/>
<input type="text" id="quantity" name="quantity[]"/>
<input id="name-data" type="text" name="price[]"/></p>
<p><input id="name" name="part_id[]"/>
<input type="text" id="quantity" name="quantity[]"/>
<input id="name-data" type="text" name="price[]"/></p>
<input id="submit" type="submit" value="Submit Order" name="submission"/>
</form>
</body>
</html>
here is What I came up with but still not working.
here is the summary of how it is working: ||Rows 1 to 4 has data > all 4 are saved || row 1 is empty and rows 2 to 3 contains data > only rows 2 and 3 are saved not row 4|| Row 2 only has data all other are empty > Data not saved || Rows 2 and 3 has data > Row 2 only is saved
<?php
include '../db/connect.php';
foreach (array('part_id', 'quantity', 'price') as $pos) {
foreach ($_POST[$pos] as $id => $row) {
$_POST[$pos][$id] = mysqli_real_escape_string($con, $row);
}
}
$ids = $_POST['part_id'];
$quantities = $_POST['quantity'];
$prices = $_POST['price'];
$items = array();
$size = count($ids);
for($i = 0 ; $i < $size ; $i++){
// Check for part id
if (empty($ids[$i]) || empty($quantities[$i]) || empty($prices[$i])) {
continue;
}
$items[]=array(
"part_id" => $ids[$i],
"quantity" => $quantities[$i],
"price" => $prices[$i]
);
}
if (!empty($items)) {
$values = array();
foreach($items as $item){
$values[] = "('{$item['part_id']}', '{$item['quantity']}', '{$item['price']}')";
}
$values = implode(", ", $values);
$sql = "INSERT INTO oz2ts_custompc_details (part_id, quantity, price) VALUES {$values} ;
" ;
$result = mysqli_query($con, $sql );
if ($result) {
echo 'Successful inserts: ' . mysqli_affected_rows($con);
} else {
echo 'query failed: ' . mysqli_error($con);
}
}
?>
The first is a simplified entry form. The reel entry form looks like this:
<!DOCTYPE html>
<html>
<head></head>
<body>
<form action="../subs/custompcorder2.php/" method="post" id="form">
<div id="orderwrap">
<div id="orderheather">
<select id="platform" name="platform">
<option selected="selected" disabled="disabled">Select the
platform</option>
<option value="Intel">Intel</option>
<option value="AMD">AMD</option>
</select>
</div>
<div id="orderbody">
<p><select id="part_id" name="part_id[]">
<option selected="selected" disabled="disabled">Choose part1 </option>
<?php query() ?>
< /select>
<input type="text" id="quantity" name="quantity[]"/>
<input id="name-data" type="text" name="price[]"/></p>
<p><select id="part_id" name="part_id[]">
<option selected="selected" disabled="disabled">Choose part2 </option>
<?php query2() ?>
< /select>
<input type="text" id="quantity" name="quantity[]"/>
<input id="name-data" type="text" name="price[]"/></p>
<p><select id="part_id" name="part_id[]">
<option selected="selected" disabled="disabled">Choose part3 </option>
<?php query3() ?>
< /select>
<input type="text" id="quantity" name="quantity[]"/>
<input id="name-data" type="text" name="price[]"/></p>
<p><select id="part_id" name="part_id[]">
<option selected="selected" disabled="disabled">Choose part4 </option>
<?php query4() ?>
< /select>
<input type="text" id="quantity" name="quantity[]"/>
<input id="name-data" type="text" name="price[]"/></p>
<input id="submit" type="submit" value="Submit Order"name="submission"/>
</div>
</div>
</form>
</body>
</html>
Here is the php page containing function query(),query1(),..
<?php
include '../db/connect.php';
function query(){
global $con;
$myData=mysqli_query($con,"SELECT * FROM oz2ts_mijoshop_product");
while($record=mysqli_fetch_array($myData)){
echo'<option value="'.$record['product_id'].'">'.$record['model'].'</option>';
}
}
function query2(){
global $con;
$myData=mysqli_query($con,"SELECT * FROM oz2ts_mijoshop_product");
while($record=mysqli_fetch_array($myData)){
echo'<option value="'.$record['product_id'].'">'.$record['model'].'</option>';
}
}
function query3(){
global $con;
$myData=mysqli_query($con,"SELECT * FROM oz2ts_mijoshop_product");
while($record=mysqli_fetch_array($myData)){
echo'<option value="'.$record['product_id'].'">'.$record['model'].'</option>';
}
}
function query4(){
global $con;
$myData=mysqli_query($con,"SELECT * FROM oz2ts_mijoshop_product");
while($record=mysqli_fetch_array($myData)){
echo'<option value="'.$record['product_id'].'">'.$record['model'].'</option>';
}
}
function close(){
mysqli_close($con);
}
?>

Sanitize input correctly using array_map
Check for input before adding to array
Only run SQL if anything to be added
Use the following code:
<?php
include '../db/connect.php';
foreach (array('part_id', 'quantity', 'price') as $pos) {
foreach ($_POST[$pos] as $id => $row) {
$_POST[$pos][$id] = mysqli_real_escape_string($con, $row);
}
}
$ids = $_POST['part_id'];
$quantities = $_POST['quantity'];
$prices = $_POST['price'];
$items = array();
$size = count($ids);
for($i = 0 ; $i < $size ; $i++){
// Check for part id
if (empty($ids[$i]) || empty($quantities[$i]) || empty($prices[$i])) {
continue;
}
$items[] = array(
"part_id" => $ids[$i],
"quantity" => $quantities[$i],
"price" => $prices[$i]
);
}
if (!empty($items)) {
$values = array();
foreach($items as $item){
$values[] = "('{$item['part_id']}', '{$item['quantity']}', '{$item['price']}')";
}
$values = implode(", ", $values);
$sql = "INSERT INTO oz2ts_custompc_details (part_id, quantity, price) VALUES {$values} ;
" ;
$result = mysqli_query($con, $sql );
if ($result) {
echo 'Successful inserts: ' . mysqli_affected_rows($con);
} else {
echo 'query failed: ' . mysqli_error($con);
}
}

Here is a rough code, modify indeces by your own needs.
$ids = $_POST['part_id'] ;
$quantities = $_POST['quantity'] ;
$prices = $_POST['price'];
$items = array();
$size = count($names);
for($i = 0 ; $i < $size ; $i++){
$items[$i] = array(
"part_id" => $ids[$i],
"quantity" => $quantities[$i],
"price" => $prices[$i]
);
}
$values = array();
foreach($items as $item){
$values[] = "('{$item['part_id']}', '{$item['quantity']}', '{$item['price']}')";
}
$values = implode(", ", $values);
$sql = "
INSERT INTO oz2ts_custompc_details (part_id, quantity, price) VALUES {$values} ;
" ;

Here's an example of basic issue handling while inserting data. Included in error checks are
Confirm that we received all 3 fields - part_id, quantity and price
If there were 3 rows of part_id, there must be 3 rows of quantity and price
Add safety by preparing INSERT statement
Bind variables to the prepared statements
Pick up only those rows in which all 3 fields (part_id, quantity and price) were entered, and that they were valid numbers
Code that receives POST
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
// debug information. Let's find what the page is receiving
echo '<pre>', print_r($_POST, true), '</pre>';
$postedData = $_POST;
// confirm that we received all 3 fields - part_id, quantity, price
$fieldsReceived = true;
if ( !confirmFields('part_id')
|| !confirmFields('quantity')
|| !confirmFields('price')
) {
echo 'part_id, quantity or price has not been received. Exiting.';
exit;
}
// confirm that each of them have identical item-count
if ( count($postedData['part_id']) !== count($postedData['quantity'])
|| count($postedData['part_id']) !== count($postedData['price'])
) {
echo count($postedData['price_id']) .
' fields received for price_id, but different number of fields
were received for quantity or price. Please ensure that part_id,
quantity and price have the same number of fields. Exiting.';
exit;
}
// establish connection using mysqli_connect
$connection = mysqli_connect('localhost', 'user', 'pass', 'selected_db');
// prepare an insert statement
$sql = 'insert into oz2ts_custompc_details
(part_id, quantity, price) values
(?, ?, ?)';
$statement = mysqli_prepare($connection, $sql);
// bind integer, integer, double to the parameters in insert statement
// corresponding to the question marks
$part = 0;
$qty = 0;
$prc = 0.0000;
mysqli_stmt_bind_param($statement, 'iid', $part, $qty, $prc);
// loop through received data and only insert those that have valid values
// in part_id, quantity and price
$partsReceived = count($postedData['part_id']);
for ($i = 0; $i < $partsReceived; $i++) {
// if drop down boxes are used and default value for part is
// Choose part, let's see if user left the selection to default
// and ignore that line
if (strpos($postedData['part_id'][$i], 'Choose part') !== false) {
continue;
}
// do we have numeric data in current line?
// although not done here, one can check if part_id is integer (is_int)
// quantity is_int and price is_float before proceeding further
if ( !is_numeric($postedData['part_id'][$i])
|| !is_numeric($postedData['quantity'][$i])
|| !is_numeric($postedData['price'][$i])
) {
echo '<p>Entry # ' . ($i + 1) . '
will be ignored because of missing
or invalid part_id, quantity, or price</p>';
continue;
}
// update bind parameters
$part = $postedData['part_id'][$i];
$qty = $postedData['quantity'][$i];
$prc = $postedData['price'][$i];
// execute statement and move on to the next one
try {
mysqli_stmt_execute($statement);
echo '<p>Inserted part_id ' . $postedData['part_id'][$i] . '</p>';
} catch (Exception $e) {
echo '<p>Could not enter data with part_id '
. $postedData['part_id'][$i] . '<br>'
. 'Error ' . $e->getMessage() . '</p>';
}
}
// --------------------------
// FUNCTIONS
// --------------------------
/**
* Confirm that we received part_id, quantity and price from POST
*
* #param string $fieldName Name of the field to verify
*
* #return bool True if fieldname is set as an array; False otherwise
*/
function confirmFields($fieldName)
{
global $postedData;
return
(!isset($postedData[$fieldName]))
&& !is_array($postedData[$fieldName]) ? false : true;
}
?>

Related

Validate checkboxes values in PHP

I have a group of checkboxes with different values each. I want to assign their values in php variables which i'm going to send to database. The main problem is that i don't know how to check inside the php code if the values of selected items matching their default values which i setup in the html (apple == apple, samsung == samsung) and so on. This is because someone can just change the input value inside the console and insert whatever he likes in my DB. Any ideas how i can sort this out. Many thanks!
<form action="" method="POST">
<label for="apple">Apple</label>
<input id="apple" type="checkbox" name="myCheckBoxes[]" value="Apple">
<label for="samsung">Samsung</label>
<input id="samsung" type="checkbox" name="myCheckBoxes[]" value="Samsung">
<label for="lenovo">Lenovo</label>
<input id="lenovo" type="checkbox" name="myCheckBoxes[]" value="Lenovo">
<label for="google">Google Pixel</label>
<input id="google" type="checkbox" name="myCheckBoxes[]" value="Google Pixel">
<button type="submit" name="submit">Send</button>
</form>
PHP Code:
if (isset($_POST['submit'])) {
$checkBoxes = $_POST['myCheckBoxes'];
$numberSelected = count($checkBoxes);
if ($numberSelected > 3) {
echo 'Please select only 3 from the options';
} else {
for ($i = 0; $i < $numberSelected; $i++) {
$option1 = $checkBoxes[0];
$option2 = $checkBoxes[1];
$option3 = $checkBoxes[2];
}
echo 'You have selected', ' ', $option1, ' ', $option2, ' ', $option3;
}
}
You can define a constant array with the allowed values, then only use values from that array when they correspond to the input value.
const ALLOWED_VALUES = [
"apple" => "Apple",
"samsung" => "Samsung",
"lenovo" => "Lenovo",
"google pixel" => "Google Pixel",
];
if (isset($_POST['submit'])) {
$checkBoxes = $_POST['myCheckBoxes'];
$options = [];
if (count($checkBoxes) > 3) {
echo 'Please select only 3 from the options';
} else {
foreach($checkBoxes as $box) {
$box = strtolower(trim($box));
if(array_key_exists($box, ALLOWED_VALUES)){
$options[] = ALLOWED_VALUES[$box];
}
}
$option1 = (array_key_exists(0, $options))? $options[0]: null;
$option2 = (array_key_exists(1, $options))? $options[1]: null;
$option3 = (array_key_exists(2, $options))? $options[2]: null;
echo 'You have selected', ' ', $option1, ' ', $option2, ' ', $option3;
}
}
The code above will accept "APPLE" but will use "Apple" anything not found or empty will be set to null. Run it live here: https://onlinephp.io/c/8409e
you can do it through the help of or (||) , and (&&) operator in else part of if condition.
if(($option1=='Apple' || $option1=='Samsung' || $option1=='Lenovo'||$option1=='Google Pixel') && ($option2=='Apple' || $option2=='Samsung' || $option2=='Lenovo'||$option2=='Google Pixel') && ($option3=='Apple' || $option3=='Samsung' || $option3=='Lenovo'||$option3=='Google Pixel')){
echo 'You have selected', ' ', $option1, ' ', $option2, ' ', $option3;
}else{
echo"Please select suggested checkbox";
}

multiple checkbox and price calculation using php

i have table service in database db.
it has 3 fields
id,
service_type,
amount.
i have html form which has checkbox to select service type,i got service type selected but amount must be calculated auto and store in database amount column. but one error when i select service from checkbox it is selected and store in database but price is not stored.
my script is as follow:
<input type="checkbox" name="services[]" value="oilchange"
<input type="checkbox" name="services[]" value="acrepair"
<input type="checkbox" name="services[]" value="tyrechange"
<input type="submit" name="btnservice" value="Confirm Services">
now php script is as follow:
<?php $price=0.0;if (isset($_POST['services'])) {
$service=$_POST['services'];
$c=count($service);
for ($i=0; $i < $c; $i++) {
if ($service[$i]==fullservice) {
$price=$price+5000;
$iq="INSERT INTO tblservices( amount) VALUES ('$price')";
$run=mysqli_query($con,$iq);
if ($run) {
}
}
elseif ($service[$i]==tyrebalance) {
# code...
$price=$price+4000;
$iq="INSERT INTO tblservices( amount) VALUES ('$price')";
$run=mysqli_query($con,$iq);
if ($run) {
}
}
elseif($service[$i]==oilchange) {
# code...
$price=$price+3000;
$iq="INSERT INTO tblservices( amount) VALUES ('$price')";
$run=mysqli_query($con,$iq);
if ($run) {
}
}
elseif ($service[$i]==acrepair) {
# code...
$price=$price+2000;
$iq="INSERT INTO tblservices( amount) VALUES ('$price')";
$run=mysqli_query($con,$iq);
if ($run) {
}
}
elseif ($service[$i]==tyrechange) {
# code...
$price=$price+1000;
$iq="INSERT INTO tblservices( amount) VALUES ('$price')";
$run=mysqli_query($con,$iq);
if ($run) {
}
}
}
}if (isset($_POST['btnservice'])) {
$a=$_POST['services'];
$type=implode("/",$a);
$query="insert into tblservices(service_type,amount) values('$type','$price')";
$run=mysqli_query($con,$query);
if ($run) {
echo "<script type = \"text/javascript\">
alert(\"Services Selected.................\");
window.location = (\"services.php\")
</script>";
}
else{
echo "<script type = \"text/javascript\">
alert(\"Login Failed. Try Again................\");
window.location = (\"services.php\")
</script>";
}
}?>
i'm new guys sorry that's why i cann't upload images i need to earn reputations so i could able to post images for better or detailed explanation of my question.
i could see two type of queries in your sample.
Sharing here single service types insertion and insertion with total price. Hope this helps!!
<div class="container">
<form action="" method="post">
<input type="checkbox" name="services[]" value="oilchange" />oilchange
<input type="checkbox" name="services[]" value="acrepair" />acrepair
<input type="checkbox" name="services[]" value="tyrechange" />tyrechange
<br/>
<input type="submit" name="btnservice" value="Confirm Services">
</form> <?php
$serviceChargeArr = array(
'fullservice' => 5000,
'tyrebalance' => 4000,
'oilchange' => 3000,
'acrepair' => 2000,
'tyrechange' => 1000
);
$priceTotal = 0.0;
if (isset($_POST['btnservice'])) {
if (isset($_POST['services'])) {
$serviceArr = $_POST['services'];
$serviceArrCnt = count($serviceArr);
//QUERY 1 - insert each with respect to clicked checkboxes
for ($i = 0; $i < $serviceArrCnt; $i++) {
if ($eachPrice = $serviceChargeArr[$serviceArr[$i]]) {
$insertArr[] = "('$serviceArr[$i]', '$eachPrice')";
}
}
if (!empty($insertArr)) {//sigle insert query -each service and its price will be inserted
$query="insert into tblservices (service_type, amount)
values".implode(", ",$insertArr ).";";
echo $query."<br/>";
}//QUERY 1 ENDS
//QUERY 2 - insert single row with comma separated values and total price
for ($i = 0; $i < $serviceArrCnt; $i++) {
if ($eachPrice = $serviceChargeArr[$serviceArr[$i]]) {
$priceTotal += $eachPrice;
}
}
if (!empty($serviceArr)) {
$seviceList = implode(',', $serviceArr);
$query="insert into tblservices (service_type, amount)
values ('{$seviceList}' , '{$priceTotal}') ;";
echo $query."<br/>";
}//QUERY 2 ENDS
if($query) {
$run = mysqli_query($con, $query);
if ($run) {
echo "<br/> SUCCESS : inserted";
} else {
echo "<br/> ERROR : try again<br/>Mysql Error: ".$con->error;
}
}
}
} ?>
</div>

No records displayed in PHP search form

can anyone tell me why this code doesn't give me any records and display my "else" error message instead ? table which I'm trying to get data from( attached) uses two foreign keys ( emp number ,and project code) from two other tabels
( Please note I'm new to PHP )
$emp_no="";
$project_code="";
$p_hours="";
require_once 'connect.php';
function getposts()
{
$posts= array();
if (isset($_POST['EMPNo']))
{
$posts[0] = $_POST['EMPNo'];
}
if (isset($_POST['ProjectCode']))
{
$posts[1] = $_POST['ProjectCode'];
}
if (isset($_POST['Hours']))
{
$posts[2] = $_POST['Hours'];
}
return $posts;
}
if(isset($_POST['search']))
{
#$data = getposts();
#$searchquery = "SELECT * FROM `enrolment` WHERE `EMPNo`='$data[0]' AND
`ProjectCode`='$data[1]'";
#$search_Result =mysqli_query($connect, $searchquery);
if($search_Result)
{
if(mysqli_num_rows($search_Result))
{
while($raw = mysqli_fetch_array($search_Result))
{
$emp_no = $raw ['EMPNo'] ;
$project_code = $raw ['ProjectCode'] ;
$p_hours = $raw ['Hours'] ;
}
}else {
echo 'Unable to find the record please check input data!';
}
}else {
echo ' Result Error ';
}
}
//html part
<Form action="updateenrolment.php" method="post" style="color:blue;margin-
left:500px;">
<input type="text" name ="empno" placeholder="Employee No" value="<?php
echo $emp_no;?>"><br><br>
<input type="text" name ="pcode" placeholder="Project Code" value="<?php
echo $project_code;?>"><br><br>
<input type="number" name ="hours" placeholder="Hours" value="<?php echo
$p_hours;?>"><br><br>
<div>
<input type="submit" name ="search" value="Find" >
mysqli_fetch_array print the array result but you are fetching result using string element. you need to change this.
while($raw = mysqli_fetch_array($search_Result))
{
$emp_no = $raw [1] ;
$project_code = $raw [2] ;
$p_hours = $raw [3] ;
}
To replace it.
while($raw = mysqli_fetch_array($search_Result))
{
$emp_no = $raw ['EMPNo'] ;
$project_code = $raw ['ProjectCode'] ;
$p_hours = $raw ['Hours'] ;
}

Inserting Array values from form into mysql

I have 3 PHP files, in select.php file you have to select the number of forms that you want.. the form contain 3 input fields.
as below:
<form method="post" action="index.php" >
Continue insertion with <select name="counters" id="insert_rows">
<option value="1">1</option>
<option value="2" selected="selected">2</option>
<option value="3">3</option>
</select>
rows
<input type="submit" value="Go" />
</form>
After selecting the number of insertions, it will pass the number to index.php which is contain:
<?php
echo "<form method = 'POST' action = 'process.php'>";
for($counter = 0; $counter < $_POST['counters']; $counter++)
{
echo "Service Name: <input type = 'text' name = 'name[]' class = 'class_name'/><br/>";
echo "Service Version : <input type = 'text' name = 'version[]' class = 'class_name'/><br/>";
echo "Service type : <input type = 'text' name = 'type[]' class = 'class_name'/><br/>";
}
echo "<input type = 'submit' value = 'SEND'/>";
echo "</form>";
?>
the third file process.php contain
<?php
$name = array();
$version = array();
$type= array();
$name = $_POST['name'];
$version = $_POST['version'];
$type= $_POST['type'];
for($counter = 0; $counter < sizeof($name); $counter++)
{
echo "service_name #".($counter + 1).": ".$name[$counter]."<br />";
echo "service_version #".($counter + 1).": ".$version[$counter]."<br />";
echo "service_type #".($counter + 1).": ".$type[$counter]."<br />";
}
?>
and after i pass the value to it, it shows the data correctly as below
service_name #1: noway
service_version #1: v1
service_type #1: Private
service_name #2: bandar
service_version #2: v2
service_type #2: Public
so my question is : how to create a function in 'process.php' file to insert all these values into the database.
I created a table called 'services' contain these columns "name,version,type"
I will be waiting for your support.
thank you
I would recommend to save the first submitted count value in an hidden input in the second form, then you will be able to loop through that and insert your data
<?php
echo "<form method = 'POST' action = 'process.php'>";
for($counter = 0; $counter < $_POST['counters']; $counter++)
{
echo "Service Name: <input type = 'text' name = 'name[]' class = 'class_name'/><br/>";
echo "Service Version : <input type = 'text' name = 'version[]' class = 'class_name'/><br/>";
echo "Service type : <input type = 'text' name = 'type[]' class = 'class_name'/><br/>";
}
echo '<input type="hidden" name="cntr" value="'.$_POST['counters'].'" />'
echo "<input type = 'submit' value = 'SEND'/>";
echo "</form>";
?>
Now in your process.php you will have:
if (!empty($_POST['cntr'])) {
$query = 'INSERT INTO services (name, version, type) VALUES ';
for ($x = 0; $x < $_POST['cntr']; $x++)
{
$query .= "('".mysqli_escape_string($_POST['name'][$x])."','"
.mysqli_escape_string($_POST['version'][$x])."','"
.mysqli_escape_string($_POST['type'][$x]).
"'),";
}
$query = substr_replace($query, '', -1);
mysqli->query($query);
}
Whatever I prepared is just a sample you can modify it base on your changes

PHP Cannot use a scalar value as an array - Incrementing a session

I am writing a script to place an order which will be added to a cart, I am storing the selected values for the cart as a session. Each new selection (addition to the cart) is added to a new session which is incremented by one each time.
ie.
$_SESSION['cart'][1]
$_SESSION['cart'][2]
$_SESSION['cart'][3]
I am receiving the below error and am stumped.
Warning: Cannot use a scalar value as an array in C:\wamp\www\php\cart\carting\order.php on line 37 -(This is the line $_SESSION['cart'][$p] = $cartstring;)
<?PHP
session_start();
$productlist = $_POST['products']; //Form post
if (isset($productlist)) {
if (!isset($_SESSION['cart'])) {
$p = 0;
$_SESSION['cart'][$p];
print $_SESSION['cart'][$p];
}
elseif (isset($_SESSION['cart'])) {
$p = count($_SESSION['cart']);
$p++;
$product = explode('-', $productlist[1][0]);
$productname = $product[0];
$productprice = $product[1];
$productqty = $productlist[1][1];
$itemsubtotal = ($productprice * $productqty);
$cartstring = "productid-$productname-$productprice-$productqty-$itemsubtotal";
$_SESSION['cart'][$p] = $cartstring; //THIS IS LINE 37
}
}
$product1 = "Bread";
$price1 = 12;
$product2 = "Butter";
$price2 = 2;
print '<form action="order.php" method="post">';
print '<input type="checkbox" name="products[1][]" value="'.$product1." "."-"." ".$price1.'" />';echo $product1;
print '<input type="text" name="products[1][]" value="" />QTY';print '<br>';
print '<br>';print '<br>';
print '
<input type="submit" name="formSubmit" value="Submit" />
</form>';
?>

Categories