cart.php
have that form
<form action=“process.php” methodd=“POST”>
<input type=“hidden” name=“id” value=‘“.$product_id.”’>
<input type=“hidden” name=“name” value=‘“.$name.”’>
<input type=“hidden” name=“quantity” value=‘“.$quantity.”’>
<input type=“hidden” name=“hello” value=‘“.$price.”’>
<input type=“submit” value=“place order”/>
</form>
process.php
<?php
foreach($_POST as $key=>$value)
echo ‘$value’;
?>
problem is at last i want to insert all posted 4 items in database but i don’t know how to do this plz help meeee
gokulgg
2
foreach($_POST as $key=>$value){
if($key == 1){ $values = “(1, ‘abc’, 2, ‘xyz’)”; }
else { $values .= “, (2, ‘abcd’, 2, ‘wxyz’)” }
}
so the $values will be (1, ‘abc’, 2, ‘xyz’), (2, ‘abcd’, 2, ‘wxyz’), (2, ‘abcd’, 2, ‘wxyz’) if $key count 3
So you can query like
INSERT INTO table (id, name, value, value2) VALUES $values;
Cups
3
- Create your form properly in the first place:
<form action="process.php" method="POST">
<input type="hidden" name="id" value='".$product_id."'>
<input type="hidden" name="name" value='".$name."'>
<input type="hidden" name="quantity" value='".$quantity."'>
<input type="hidden" name="hello" value='".$price."'>
<input type="submit" value="place order"/>
</form>
Its not “methodd” but “method”.
- Show us how your database table is made up.
It’s simple to put the data into a database.
Have your connection ready:
$db = new mysqli("host","user","password","database");
Then make variable for the post data:
$id = $_POST['id'];
$name = $_POST['name'];
etc.
Then insert it into the database using the connection you made:
$query = "insert into tablename(id, name, etc.) values($id, $name, etc.);
$insert = $db->query($query);
Make sure to have some error and success messages on your process.php