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>';
?>
Related
I have been trying to find this out for weeks and I'm not seeing it. how do I store the quantities alongside the products which the user has added to their cart? I need to have this because I need the users to be able to update the quantity from the items.
already tried a few things such as creating an array and trying to store quantity in a array but it only remembers the last number that the user put in. This is because its a post request. and to fix that I need to store quantities alongs side the products in cart. and thats where I'm stuck.
I tried:
if(isset($_POST['quantity'])){
$quantity = $_POST['quantity'];
$_SESSION['basket'][] = $quantity;
}
but this put the last item a lot in the shopping cart
like this:
then I tried:
if (isset($_POST['quantity']) && !empty($_POST['quantity'])){
$_SESSION['quantity'] = $_POST['quantity'];
// //$qty = $_SESSION["qty"] + 1;
if (isset($_POST['broodnaam']) && !empty($_POST['broodnaam'])){
if ($_POST['broodnaam'] == $row['broodnaam']){
$quantity = $_POST['quantity'];
// //array_push($_SESSION['qty'], $quantity);
// // var_dump($_SESSION['qty']);
}
}
}
but this only updates the last updated item from the cart.
I really don't know how to fix this can someone help me
code: ( part of the code as I don't feel like I need to share the styling and sessions_start() part
<?php
$broodjes = $_GET['broodjes_ID'];
if (isset($_SESSION['basket'])){
if( in_array( $broodjes ,$_SESSION['basket']) )
{
}else{
$_SESSION['basket'][] = $broodjes;
}
}else{
$_SESSION['basket'][]= $broodjes;
}
$sumtotal = 0;
foreach($_SESSION['basket'] as $key => $value){
//echo "Key = $key; value = $value; <br>";
$sql = "SELECT broodjes_ID, broodnaam, prijs, voorraad FROM broodjes WHERE broodjes_ID=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $value);
$stmt->execute();
$result = $stmt->get_result();
if($row = $result->fetch_assoc()){
//session for quantity
$_SESSION["qty"] = array();
echo '<div class="cart-items">';
echo '<div class="cart-row">';
echo '<div class="cart-item cart-column">';
echo $row['broodnaam'];
echo '</div>';
echo '<div class="cart-item cart-column">';
echo '€ ' . $row['prijs'];
echo '</div>';
//quantity
echo '<div class="cart-item cart-column">';
echo '<form method="POST" action="">';
echo '<div class="col-xs-4">';
echo '<input type="hidden" name="broodnaam" id="broodnaam" value="' . $row['broodnaam'] . '">';
echo '<input type="number" name="quantity" id="quantity" class="form-control input-sm" value="1" min="1" max="'.$row['voorraad'].'">';
echo '</div>';
echo '</form>';
echo '</div>';
//ik moet de quantity ergens in opslaan , denk in db, om zo nog de voorraad te verminderen
if (isset($_POST['quantity']) && !empty($_POST['quantity'])){
$_SESSION['quantity'] = $_POST['quantity'];
// //$qty = $_SESSION["qty"] + 1;
if (isset($_POST['broodnaam']) && !empty($_POST['broodnaam'])){
if ($_POST['broodnaam'] == $row['broodnaam']){
$quantity = $_POST['quantity'];
////array_push($_SESSION['qty'], $quantity);
//// var_dump($_SESSION['qty']);
}
}
}
echo '<div class="cart-item cart-column">';
$rowtotaal = $row['prijs'] * $quantity;
$sumtotal += $rowtotaal;
echo $rowtotaal;
echo '</div>';
echo '</div>';
echo '</div>';
}
}
?> <br />
<div class="cart-total">
<strong class="cart-total-title">Total</strong>
<span class="cart-total-price"> € <?php echo $sumtotal;?></span>
</div>
<br/>
what you need is a unique column in your products' table.
generally, the unique column is either id or alias.
Then when you need to add an item to the cart:
// supposing you have the product id in the $pid variable and quantity in the $qty variable
$_SESSION['cart'][$pid] = $qty;
Then when you need to access it you can easily loop through the session's cart.
foreach($_SESSION['cart'] as $product => $qty) {
// do something with the product and quantity.
}
how this works is, it creates an item in the cart array with the index of the product's unique column value and the item's value would be the quantity of the product added to the cart.
Update the new quantity ($_POST['quantity']) by adding the old one ($_SESSION['qty']).like this -
if (isset($_POST['quantity'])){
if (isset($_POST['broodnaam'])){
if ($_POST['broodnaam'] == $row['broodnaam']){
$_SESSION['qty'] = $_POST['quantity'] + $_SESSION['qty'];
}
}
}
I am having issues with my PHP code. I am trying to insert data into a mysql database with Session variables info. The connection to the SQL table is fine. Whenever i submit the form it displays none of the session variables. The code is quite lengthy. Any help would be highly appreciated.
View Cart Page
<h1 align="center">View Cart</h1>
<div class="cart-view-table-back">
<form method="post" action="cart_update.php">
<table width="100%" cellpadding="6" cellspacing="0"><thead><tr><th>Quantity</th><th>Name</th><th>Price</th><th>Total</th><th>Remove</th></tr></thead>
<tbody>
<?php
if(isset($_SESSION["cart_products"])) //check session var
{
$total = 0; //set initial total value
$b = 0; //var for zebra stripe table
foreach ($_SESSION["cart_products"] as $cart_itm)
{
//set variables to use in content below
$product_name = $cart_itm["product_name"];
$product_qty = $cart_itm["product_qty"];
$product_price = $cart_itm["product_price"];
$product_code = $cart_itm["product_code"];
$product_color = $cart_itm["product_color"];
$subtotal = ($product_price * $product_qty); //calculate Price x Qty
$bg_color = ($b++%2==1) ? 'odd' : 'even'; //class for zebra stripe
echo '<tr class="'.$bg_color.'">';
echo '<td><input type="text" size="2" maxlength="2" name="product_qty['.$product_code.']" value="'.$product_qty.'" /></td>';
echo '<td>'.$product_name.'</td>';
echo '<td>'.$currency.$product_price.'</td>';
echo '<td>'.$currency.$subtotal.'</td>';
echo '<td><input type="checkbox" name="remove_code[]" value="'.$product_code.'" /></td>';
echo '</tr>';
$total = ($total + $subtotal); //add subtotal to total var
}
$grand_total = $total + $shipping_cost; //grand total including shipping cost
foreach($taxes as $key => $value){ //list and calculate all taxes in array
$tax_amount = round($total * ($value / 100));
$tax_item[$key] = $tax_amount;
$grand_total = $grand_total + $tax_amount; //add tax val to grand total
}
$list_tax = '';
foreach($tax_item as $key => $value){ //List all taxes
$list_tax .= $key. ' : '. $currency. sprintf("%01.2f", $value).'<br />';
}
$shipping_cost = ($shipping_cost)?'Shipping Cost : '.$currency. sprintf("%01.2f", $shipping_cost).'<br />':'';
}
?>
<tr><td colspan="5"><span style="float:right;text-align: right;"><?php echo $shipping_cost. $list_tax; ?>Amount Payable : R <?php echo sprintf("%01.2f", $grand_total);?></span></td></tr>
<tr><td colspan="5">Add More Items<button type="submit">Update</button></td></tr>
</tbody>
</table>
<input type="hidden" name="return_url" value="<?php
$current_url = urlencode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
echo $current_url; ?>" />
</form>
</div>
</form>
</form>
The cart update Page
<?php
session_start();
include_once("config.php");
//add product to session or create new one
if(isset($_POST["type"]) && $_POST["type"]=='add' && $_POST["product_qty"]>0)
{
foreach($_POST as $key => $value){ //add all post vars to new_product array
$new_product[$key] = filter_var($value, FILTER_SANITIZE_STRING);
}
//remove unecessary vars
unset($new_product['type']);
unset($new_product['return_url']);
//we need to get product name and price from database.
$statement = $mysqli->prepare("SELECT product_name, price FROM products WHERE product_code=? LIMIT 1");
$statement->bind_param('s', $new_product['product_code']);
$statement->execute();
$statement->bind_result($product_name, $price);
while($statement->fetch()){
//fetch product name, price from db and add to new_product array
$new_product["product_name"] = $product_name;
$new_product["product_price"] = $price;
if(isset($_SESSION["cart_products"])){ //if session var already exist
if(isset($_SESSION["cart_products"][$new_product['product_code']])) //check item exist in products array
{
unset($_SESSION["cart_products"][$new_product['product_code']]); //unset old array item
}
}
$_SESSION["cart_products"][$new_product['product_code']] = $new_product; //update or create product session with new item
}
}
//update or remove items
if(isset($_POST["product_qty"]) || isset($_POST["remove_code"]))
{
//update item quantity in product session
if(isset($_POST["product_qty"]) && is_array($_POST["product_qty"])){
foreach($_POST["product_qty"] as $key => $value){
if(is_numeric($value)){
$_SESSION["cart_products"][$key]["product_qty"] = $value;
}
}
}
//remove an item from product session
if(isset($_POST["remove_code"]) && is_array($_POST["remove_code"])){
foreach($_POST["remove_code"] as $key){
unset($_SESSION["cart_products"][$key]);
}
}
}
//back to return url
$return_url = (isset($_POST["return_url"]))?urldecode($_POST["return_url"]):''; //return url
header('Location:'.$return_url);
?>
The page im having issues with, Insert Variables.php
<?
$product_name = $_SESSION["product_name"];
$product_qty = $_SESSION["product_qty"];
$product_price = $_SESSION["product_price"];
$hostname="Localhost";
$username="ABCD";
$password="";
$dbname="Abc";
$usertable="Shop";
$link = mysqli_connect($hostname,$username,$password,$dbname);
if(isset($_POST['submit'])){
$product_name = $_SESSION["product_name"];
$product_qty = $_SESSION["product_qty"];
$product_price = $_SESSION["product_price"];
}
if($link === false) {
die("Error: Could not connect.".mysqli_connect_error());
}
$sql = "INSERT INTO $usertable (Qty, product,productID) VALUES ('{$_SESSION['product_qty']}', '{$_SESSION['product_name']}', '{$_SESSION['cart_products']}')";
if (mysqli_query($link, $sql)){
echo "<h1> Succes </h1>";
} else {
echo "Error: could not execute $sql. " . mysqli_error($link);
}
mysqli_close($link);
?>
I guess the problem is at the very beginning of the Variables.php
You have:
$product_name = $_SESSION["product_name"];
$product_qty = $_SESSION["product_qty"];
$product_price = $_SESSION["product_price"];
But instead, it should be:
$product_name = $_SESSION["cart_products"][$key]["product_name"];
$product_qty = $_SESSION["cart_products"][$key]["product_qty"];
$product_price = $_SESSION["cart_products"][$key]["product_price"];
Where $key is the product_code
Then use the varibales
$sql = "INSERT INTO $usertable (Qty, product, productID) VALUES ('$product_qty', '$product_name', '$key'";
I have created an add to cart functionality I am not pretty sure if I have developed perfectly or not.
when I am trying to add new session cart item it is not setting up for me the quantity, and pid is inserting properly, but the other two options I am unable to store though like if i try to create a variable $_SESSION['cart']['pid'].
it is working fine but when I try to add another session variable $_SESSION['cart']['option1'] it is not working
if(isset($_POST['cart'])) {
$pid = $_POST['product_id'];
$qty = $_POST['qty'];
$opt1 = $_POST['opt1'];
$opt2 = $_POST['opt2'];
if(isset($_SESSION['cart']['pid'][$pid])) {
$_SESSION['cart']['pid'][$pid]++;
$_SESSION['cart']['opt1'][$pid] = $opt1;
$_SESSION['cart']['opt2'][$pid] = $opt2;
if($qty > 1) {
$_SESSION['cart']['pid'][$pid] = $qty;
}
} else {
$_SESSION['cart']['pid'][$pid] = 1;
if($qty > 1) {
$_SESSION['cart']['pid'][$pid] = $qty;
}
}
}
<form method="POST" action="result.php">
<input type="text" name="product_id" placeholder="Product Id" />
<input type="text" name="qty" placeholder="Quantity" />
<input type="text" name="opt1" placeholder="A" />
<input type="text" name="opt2" placeholder="b" />
<input type="submit" name="cart" value="Add To Cart" />
</form>
Please let me know if I am on the right track and also the add to cart function is properly developed
I think you are confused, specially when you add an already-stored-in-session product:
When you already have the product_id in your cart, you write:
$_SESSION['cart']['pid'][$pid]++;
...so you lost the product_id from your pid session index.
Maybe you should just add the quantity in another pid -> variable ... instead of changing the pid value.
if(isset($_POST['cart'])) {
$pid = $_POST['product_id'];
$qty = $_POST['qty'];
$opt1 = $_POST['opt1'];
$opt2 = $_POST['opt2'];
// Create the prodcut_id array if it does not exist
if(!isset($_SESSION['cart']['pid'][$pid])) {
$_SESSION['cart']['pid'][$pid] = array();
}
// Is the same item already stored? (same opt1 and opt2)
$sameItem = false;
if (!empty($_SESSION['cart']['pid'][$pid])) {
foreach ($_SESSION['cart']['pid'][$pid] as $key => $product) {
// Same options item?
if ($product['opt1'] == $opt1 &&
$product['opt2'] == $opt2) {
$sameItem = $key;
}
}
}
if ($sameItem !== false) {
// Change the quantity
$_SESSION['cart']['pid'][$pid][$sameItem]['qty'] += $qty;
} else {
// Store the item as new array key
array_push($_SESSION['cart']['pid'][$pid],
array('qty' => $qty, 'opt1' => $opt1, 'opt2' => $opt2);
}
}
By the way, are you using session_start() properly?
With the foreach loop I'm trying to connect to my database and display in a list the products that have been added to the cart. Each product has a product ID which is correctly working and being stored in the session variable through the cart.php. I can't figure out how to connect to the database to display the information gathered about the product added - I also tried doing var_dump $SESSION['cart'] and its prints out null even after I use the "Add" button in cart.php.
<div class="row">
<h4>Shopping Cart</h4>
<?php
foreach($_SESSION['cart'] as $proid => $proq) {
// $proid is product id and $proq is quantity
// use $proid to select the product detail from database
}
?>
</div>
<!--Below is my cart.php page-->
<?php
session_start();
$productID = $_GET['product'];
$action = $_GET['action'];
switch($action) {
case "add":
$_SESSION['cart'][$productID]++;
break;
case "remove":
$_SESSION['cart'][$productID]--;
if($_SESSION['cart'][$productID] == 0) unset($_SESSION['cart'][$productID]);
break;
case "empty":
unset($_SESSION['cart']);
break;
}
header("Location: browse.php");
?>
For product view (index.php)
<?php
//current URL of the Page. cart_update.php redirects back to this URL
$current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$results = $mysqli->query("SELECT * FROM products");
if ($results) {
//fetch results set as object and output HTML
while($obj = $results->fetch_object())
{
echo '<div class="product">';
echo '<form method="post" action="update_cart.php">';
echo '<div class="product-content">';
echo '<div class="product-info">';
echo 'Price '.$currency.$obj->price.' | ';
echo 'Qty <input type="text" name="product_qty" value="1" size="3" />';
echo '<button class="add_to_cart">Add To Cart</button>';
echo '</div></div>';
echo '<input type="hidden" name="product_code" value="'.$obj->product_code.'" />';
echo '<input type="hidden" name="type" value="add" />';
echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
echo '</form>';
echo '</div>';
}
}
?>
For Update cart (Update_cart.php)
//add item in shopping cart
if(isset($_POST["type"]) && $_POST["type"]=='add')
{
$product_code = filter_var($_POST["product_code"], FILTER_SANITIZE_STRING); //product code
$product_qty = filter_var($_POST["product_qty"], FILTER_SANITIZE_NUMBER_INT); //product code
$return_url = base64_decode($_POST["return_url"]); //return url
ySqli query - get details of item from db using product code
$results = $mysqli->query("SELECT product_name,price FROM products WHERE product_code='$product_code' LIMIT 1");
$obj = $results->fetch_object();
if ($results) { //we have the product info
//prepare array for the session variable
$new_product = array(array('name'=>$obj->product_name, 'code'=>$product_code, 'qty'=>$product_qty, 'price'=>$obj->price));
if(isset($_SESSION["products"])) //if we have the session
{
$found = false; //set found item to false
foreach ($_SESSION["products"] as $cart_itm) //loop through session array
{
if($cart_itm["code"] == $product_code){ //the item exist in array
$product[] = array('name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$product_qty, 'price'=>$cart_itm["price"]);
$found = true;
}else{
//item doesn't exist in the list, just retrive old info and prepare array for session var
$product[] = array('name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$cart_itm["qty"], 'price'=>$cart_itm["price"]);
}
}
if($found == false) //we didn't find item in array
{
//add new user item in array
$_SESSION["products"] = array_merge($product, $new_product);
}else{
//found user item in array list, and increased the quantity
$_SESSION["products"] = $product;
}
}else{
//create a new session var if does not exist
$_SESSION["products"] = $new_product;
}
}
//redirect back to original page
header('Location:'.$return_url);
}
For View Cart(View_cart.php)
<?php
$current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
if(isset($_SESSION["products"]))
{
$total = 0;
echo '<form method="post" action="checkout.php">';
echo '<ul>';
$cart_items = 0;
foreach ($_SESSION["products"] as $cart_itm)
{
$product_code = $cart_itm["code"];
$results = $mysqli->query("SELECT product_name,product_desc, price FROM products WHERE product_code='$product_code' LIMIT 1");
$obj = $results->fetch_object();
echo '<li class="cart-itm">';
echo '<span class="remove-itm">×</span>';
echo '<div class="p-price">'.$currency.$obj->price.'</div>';
echo '<div class="product-info">';
echo '<h3>'.$obj->product_name.' (Code :'.$product_code.')</h3> ';
echo '<div class="p-qty">Qty : '.$cart_itm["qty"].'</div>';
echo '<div>'.$obj->product_desc.'</div>';
echo '</div>';
echo '</li>';
$subtotal = ($cart_itm["price"]*$cart_itm["qty"]);
$total = ($total + $subtotal);
echo '<input type="hidden" name="item_name['.$cart_items.']" value="'.$obj->product_name.'" />';
echo '<input type="hidden" name="item_code['.$cart_items.']" value="'.$product_code.'" />';
echo '<input type="hidden" name="item_desc['.$cart_items.']" value="'.$obj->product_desc.'" />';
echo '<input type="hidden" name="item_qty['.$cart_items.']" value="'.$cart_itm["qty"].'" />';
$cart_items ++;
}
echo '</ul>';
echo '<span class="check-out-txt">';
echo '<strong>Total : '.$currency.$total.'</strong> ';
echo '</span>';
echo '</form>';
}
?>
Need remove product from cart
use this in update cart (update_cart.php)
//remove item from shopping cart
if(isset($_GET["removep"]) && isset($_GET["return_url"]) && isset($_SESSION["products"]))
{
$product_code = $_GET["removep"]; //get the product code to remove
$return_url = base64_decode($_GET["return_url"]); //get return url
foreach ($_SESSION["products"] as $cart_itm) //loop through session array var
{
if($cart_itm["code"]!=$product_code){ //item does,t exist in the list
$product[] = array('name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$cart_itm["qty"], 'price'=>$cart_itm["price"]);
}
//create a new product list for cart
$_SESSION["products"] = $product;
}
//redirect back to original page
header('Location:'.$return_url);
}
Create database connection
<?php
$db_username = 'root';//username
$db_password = '';//password
$db_name = '';//database name
$db_host = 'localhost';//your host
$mysqli = new mysqli($db_host, $db_username, $db_password,$db_name);
?>
> Important Use this in every page
<?php
error_reporting(0);
include("config.php");
session_start();
?>
Based on your explanation, you are trying to retrieve data from a session value to populate a database query.
However, when your for loop executes, you have not de-serialized the session data into memory (so it cannot be accessed and you get null values).
You need to start the session before your for loop:
session_start();
foreach($_SESSION['cart'] as $proid => $proq) {
Please see more information in the php manual
Also, you can configure PHP to start the session automatically if desired (see more details in the manual linked above), however keep in mind that this will have a performance impact even on pages which do not rely on session data.
I try to create an order page on php. I have created a form which stores data into the database. The form number is based on the user and it is created dynamic.
<?php
if(isset($_POST['submit_num']))
{
$number=$_POST['sky'];
for($i=0;$i<$number;$i++)
{
$item = $_SESSION['item'];
echo $item;
$rec_query = "SELECT * FROM ylika";
$rec_result= mysql_query($rec_query) or die("my eroors");
echo '<form action="user_order_form.php" method="POST">';
echo '<html>';
while($row_rec = mysql_fetch_array($rec_result))
{
echo '<input type="checkbox" name="yliko[]" value='.$row_rec['onoma'].'> '.$row_rec['onoma'].'';
echo '<br>';
}
echo '<br>';
echo '<input type="submit" name="submit" value="ORDER">';
echo '</form>';
}
}
?>
So I have many forms and 1 script to handle them. If I submit 1 form then it applies the data to the database but the other forms dissapear. This is the second php 'handler'.
<?php
if (isset($_POST['submit']))
{
$max_id = "SELECT MAX(id_order) FROM id_of_orders";
$x=mysql_query($max_id) or die("my eroors");
$id= mysql_fetch_array($x);
$xyz = $id['MAX(id_order)'];
$item = $_SESSION['item'];
$temp = $_POST['yliko'];
$temp2 = implode(",", $temp);
$inserts = ("INSERT INTO orders (order_id,product,ulika) VALUES ('$xyz' , '$item','$temp2')");
$inc_prod=("UPDATE proion SET Counter = Counter + 1 WHERE proion.onomasia='$item'");
mysql_query($inserts) or die(mysql_error());
mysql_query($inc_prod) or die(mysql_error());
}
?>
I want to submit all the forms. Should I try to create one submit button for all of the forms or is there a way to handle all of them separately ?
You can have many submit forms, but simply define one big <form> with all of them, then you will not lose any information.
<?php
if(isset($_POST['submit_num']))
{
$number=$_POST['sky'];
echo '<form action="user_order_form.php" method="POST">';
for($i=0;$i<$number;$i++)
{
$item = $_SESSION['item'];
echo $item;
$rec_query = "SELECT * FROM ylika";
$rec_result= mysql_query($rec_query) or die("my eroors");
echo '<html>';
while($row_rec = mysql_fetch_array($rec_result))
{
echo '<input type="checkbox" name="yliko[]" value='.$row_rec['onoma'].'> '.$row_rec['onoma'].'';
echo '<br>';
}
echo '<br>';
echo '<input type="submit" name="submit" value="ORDER">';
}
echo '</form>';
}
?>
now you can also add the ~$i~ identifier to input names, so you can easily distinguish which is which.