I have created a form that contains about 20 lines of entry. When user user navigate away after starting filling the form he will start over after coming back. I want to save data on the form until user decided to reset or save. I red some docs about session and cookies but do not know haw to insert it on my form. Can some one hel me achieving this?
entry form
<?php session_start();
?>
<form action="../action/subs/custompcorder.php/" method="post" id="ccomputer" >
<div id="intel">
<ul>
<li >
<input id="name" name="part_id[]" type="text"/>
<input id="quantity" name="quantity[]" type="text"/>
<input id="name-data" name="price[]" type="text" />
</li>
<li >
<input id="name" name="part_id[]" type="text"/>
<input id="quantity" name="quantity[]" type="text"/>
<input id="name-data" name="price[]" type="text" />
</li>
</ul>
</div>
<input id="submit" type="submit" value="Submit Order" name="submission"/>
processing form to save data in mysql db
<?php
include '../db/connect.php';
// insert order details
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']}','$orderid')";
}
$values = implode(", ", $values);
$sql = "INSERT INTO oz2ts_custompc_details (part_id, quantity, "
. "price,order_id) VALUES {$values} ;
";
$result = mysqli_query($con, $sql);
if ($result) {
echo 'Successful inserts: ' . mysqli_affected_rows($con);
} else {
echo 'query failed: ' . mysqli_error($con);
}
}
?>