Saving session data and post it to database - php

I have a site where you can order some tickets. If someone makes an order, I want the order to be send to the database. Also I want to put the specific cart items in to be send to the database. See the model I use:
ORDERS CART ITEMS
id* id
amount order_id*
product_id
quantity
This is the code I use with the form:
<form action="index.php?page=cart" method="post" class="">
<table class=" table__nav">
<thead>
<tr>
<th class="p p--bold p--th th--ticket">Ticket</th>
<th class="p p--bold p--th th--name">Name</th>
<th class="p p--bold p--th th--quantity">Quantity</th>
<th class="p p--bold p--th th--price">Price per ticket</th>
<th class="p p--bold p--th th--itemtotal">Item Total</th>
</tr>
</thead>
<tbody>
<?php
$total = 0;
foreach($_SESSION['cart'] as $ticket) {
$ticketTotal = $ticket['ticket']['price'] * $ticket['quantity'];
$total += $ticketTotal;
?>
<tr>
<td>
<?php echo $ticket['ticket']['eye_cart']; ?>
</td>
<td>
<p class = "p--bold"><?php echo $ticket['ticket']['name']; ?></p>
</td>
<td>
<input class = "p td--quantity" type="number" name="quantity[<?php echo $ticket['ticket']['id'];?>]" value="<?php echo $ticket['quantity'];?>" class="replace" required />
</td>
<td>
<p>€<?php echo $ticket['ticket']['price'];?>,-</p>
</td>
<td>
<p>€<?php echo $ticketTotal;?>,-</p>
</td>
<td>
<td class="remove-item"><button type="submit" class="btn remove-from-cart" name="remove" value="<?php echo $ticket['ticket']['id'];?>">×</button></td>
</td>
</tr>
</tbody>
<?php } ?>
</table>
<div class="table__wrap">
<button type="submit" id="update-cart" class="btn btn--cart" name="action" value="update">
<img width="14" height="14" src="./assets/img/refresh.png" alt="refresh">
</button>
</img>
<p class="table__order--total"><span class="span--bold span--bold-no">Total:</span></p>
<p class="table__order--number"><span class="span--bold span--bold-no">€ <?php echo $total ?>,-</span></p>
</div>
<div class="table__wrap table__wrap--end">
<a class="p p__li p__li--light" href="index.php?page=register">
<button type = "submit" name ="action" value = "details" class="btn btn--big btn--big-2 btn--dark">your details -> </button></a>
</div>
</form>
When the user presses the button to go to "your details" I want to save an order with the total amount + the cart items with the order_id and quantity.
I'm using the MVC model for this but I can't really figure it out.
This is how my controller looks:
if ($_POST['action'] == 'details') {
$data = array(
'amount' => $total,
);
$insertedOrder = $this->orderDAO->insertOrder($data);
$this->set('insertedOrder', $insertedOrder);
if (empty($insertedOrder)) {
$errors = $this->orderDAO->validate($data);
$this->set('errors', $errors);
}
}
if ($_POST['action'] == 'details') {
$dataB= array(
'order_id' => ?,
'product_id' => $_SESSION['cart']['id']['ticket']['id'],
'quantity' => $_SESSION['cart']['quantity'],
);
$insertedCartItem = $this->orderDAO->insertCartItem($data);
$this->set('insertedCartItem', $insertedCartItem);
if (empty($insertedCartItem)) {
$errors = $this->orderDAO->validateB($dataB);
$this->set('errors', $errors);
}
}
And the next code is my DAO:
public function insertOrder($data){
$errors = $this->validate( $data );
if (empty($errors)) {
$sql = "INSERT INTO `orders` (`amount`) VALUES (:amount)";
$stmt = $this->pdo->prepare($sql);
$stmt->bindValue(':amount', $data['amount']);
if ($stmt->execute()) {
return $this->selectOrderById($this->pdo->lastInsertId());
}
}
return false;
}
public function insertCartItem($dataB){
$errors = $this->validateB($dataB);
if (empty($errors)) {
$sql = "INSERT INTO `cart_items` (`order_id` `product_id`,`quantity`) VALUES (:order_id, :product_id, :quantity)";
$stmt = $this->pdo->prepare($sql);
$stmt->bindValue(':order_id', $dataB['order_id']);
$stmt->bindValue(':product_id', $dataB['product_id']);
$stmt->bindValue(':quantity', $dataB['quantity']);
if ($stmt->execute()) {
return $this->selectCartItemById($this->pdo->lastInsertId());
}
}
return false;
}
The main problem I have is that I don't know how I can send data from $_SESSION variables to the database. I run into problems in the controller. As you can see I'm sending data with the $data and $dataB, but I think I'm going wrong there.

Related

Delete image(s) associated with record from folder

I have a page that allows for multiple record deletes using checkboxes and all works fine.
However, each record may have an image associated with it stored in a folder that would also need to be deleted but I have no idea how to achieve this even though I've searched Stackoverflow and Google.
How do I delete the record(s) from the MySQL database and the image(s) associated with it from the folder?
What I have so far is:
The code that deletes the records:
if ( isset( $_POST[ 'chk_id' ] ) ) {
$arr = $_POST[ 'chk_id' ];
foreach ( $arr as $id ) {
#mysqli_query( $KCC, "DELETE FROM pageContent WHERE contentID = " . $id );
}
$msg = "Page(s) Successfully Deleted!";
header( "Location: delete-familyservices.php?msg=$msg" );
}
The form that selects the records to delete:
<form name="deleteRecord" id="deleteRecord" method="post" action="delete-familyservices.php">
<?php if (isset($_GET['msg'])) { ?>
<p class="alert alert-success">
<?php echo $_GET['msg']; ?>
</p>
<?php } ?>
<table width="100%" class="table table-striped table-bordered table-responsive">
<tr>
<th>Page Title</th>
<th>Page Text</th>
<th>Page Image</th>
<th>Delete</th>
</tr>
<?php do { ?>
<tr>
<td width="30%" style="vertical-align: middle">
<h4 style="text-align: left">
<?php echo $row_rsContent['contentTitle']; ?>
</h4>
</td>
<td width="45%" style="vertical-align: middle">
<?php echo limit_words($row_rsContent['contentData'], 10); ?> ...</td>
<td align="center" style="vertical-align: middle">
<?php if (($row_rsContent['contentImage']) != null) { ?>
<img src="../images/<?php echo $row_rsContent['contentImage']; ?>" class="img-responsive">
<?php } else { ?> No Image
<?php } ?>
</td>
<td width="5%" align="center" style="vertical-align: middle"><input type="checkbox" name="chk_id" id="chk_id" class="checkbox" value="<?php echo $row_rsContent['contentID']; ?>">
</td>
</tr>
<?php } while ($row_rsContent = mysqli_fetch_assoc($rsContent)); ?>
</table>
<p> </p>
<div class="form-group" style="text-align: center">
<button type="submit" name="submit" id="submit" class="btn btn-success btn-lg butt">Delete Selected Page(s)</button>
<button class="btn btn-danger btn-lg butt" type="reset">Cancel Deletion(s)</button>
</div>
</form>
The final piece of code, which is a confirmation script:
<script type="text/javascript">
$( document ).ready( function () {
$( '#deleteRecord' ).submit( function ( e ) {
if ( !confirm( "Delete the Selected Page(s)?\nThis cannot be undone." ) ) {
e.preventDefault();
}
} );
} );
</script>
I've seen the unlink() function mentioned but I don't know if this is what to use or have any idea how to incorporate it into the existing code if it is.
you'll have to use the path of the image which is stored on you database like so :
unlink(' the link of the images which is fetched from db'); // correct
don't forget to check for image existence file_exists() //
Got this from another site and a bit of trial and error.
if($_POST) {
$arr = isset($_POST['chk_id']) ? $_POST['chk_id'] : false;
if (is_array($arr)) {
$filter = implode(',', $arr);
$query = "SELECT *filename* FROM *table* WHERE *uniqueField* IN ({$filter})";
$result = mysqli_query(*$con*, $query);
while ($row = mysqli_fetch_object($result)) {
$pathToImages = "*path/to/images*";
{
unlink("{$pathToImages}/{$row->contentImage}");
}
}
// DELETE CAN BE DONE IN ONE STATEMENT
$query = "DELETE FROM *table* WHERE *uniqueField* IN ({$filter})";
mysqli_query(*$con*, $query);
$msg = "Page(s) Successfully Deleted!";
header("Location: *your-page.php*?msg=$msg");
}
}
Thanks to everyone who contributed.
Hope this is of some help to others.

Add items in shopping basket to database

I am trying to insert the items in the shopping basket to the table userOrders within my database. The fields in Mysql are productId, Quantity and orderTotal I am aware that I should be using SSL.
I am relatively new to this so please be kind to me, any help would be greatly appreciated.
the shopping basket:
<h1>View Shopping Basket</h1>
<div class="container-fluid">
<div class="row">
<div class="col-lg-6">
<form method="post" value="placeOrder" action="<?php echo
htmlspecialchars($_SERVER['PHP_SELF']); ?>" autocomplete="off">
<form method="post" value="update" action="checkout.php?
page=cart">
<table class="table-responsive">
<thead>
<tr>
<th>productId</th>
<th>Name</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<?php
//select all from products where ID is in session
$sql="SELECT * FROM products WHERE productId IN (";
//for each session append ID and add comma's to seperate
foreach($_SESSION['cart'] as $id => $val) {
$sql.=$id.",";
}
//subtract last comma from ID's & append last bracket to
prevent error
$sql=substr($sql, 0, -1).") ORDER BY name ASC";
$query=mysql_query($sql);
$totalprice=00.00;
$quantity =0;
$productId = 'productId';
while($row=mysql_fetch_array($query)){
//running total
$subtotal=$_SESSION['cart'][$row['productId']]
['quantity']*$row['price'];
//total price added with each loop
$totalprice+=$subtotal;
?>
<tbody>
<tr>
<!--hidden productId-->
<td><?php echo $row['productId'] ?></td>
<!--display product name-->
<td><?php echo $row['name'] ?></td>
<!--display quantity-->
<!--take 'productID' & 'quantity' rows, -->
<td><input type="text" name="quantity[<?php echo
$row['productId'] ?>]" size="2" value="<?php echo $_SESSION['cart']
[$row['productId']]['quantity'] ?>" /></td>
<!--display price-->
<td><?php echo $row['price'] ?>£</td>
<!--products price == quantity of productID in
session * price -->
<td><?php echo $_SESSION['cart'][$row['productId']]
['quantity']*$row['price'] ?>£</td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" style="text-align:right">Total Price: <?
php echo $totalprice ?></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<br />
<button type="submit" value="update" name="update">Update Shopping
Basket</button>
<br />
<button type="submit" value="PlaceOrder" name="PlaceOrder">Place
Order</button>
</form>
<br />
<p style="text-align:center">To remove an item set its quantity to 0. </p>
<a href="shopsesh.php?page=products"><p style="text-align:left">Continue
Shopping</a></p>
Update Quantity:
<?php
//check form was submitted, if yes & value ==0 then unset session.
if(isset($_POST['submit'])){
foreach($_POST['quantity'] as $key => $val) {
if($val==0) {
unset($_SESSION['cart'][$key]);
//if form was submit and value =! 0 then update quantity
}else{
$_SESSION['cart'][$key]['quantity']=$val;
}
}
}
?>
Insert Query:
<?php
//add items to orders table in DB
if (isset($_POST['placeOrder'])) {
//if no error
if( !$error ) {
$productId = $_POST['productId'];
$quantity = $_POST['quantity'];
//$_POST['$totalPrice'];
//insert order into database
$query = "INSERT INTO userOrders(productId,quantity,orderTotal)
VALUES('$productId','$quantity','$totalprice')";
$res = mysql_query($query);
if ($res) {
$errTyp = "success";
$errMSG = "Items added to database";
} else {
$errTyp = "danger";
$errMSG = "Something went wrong, try again later...";
}
}
}
?>

Data from controller not going to view (PHP Codeigniter)

I'm trying to get the $data from my controller to go into my view but it does not seem to be working. I keep getting a "variable does not exist" error. Here's the Controller code (view is loaded in a different part).
$affiliate_id = $this->input->get_post('affiliate_id');
$product_id = $this->input->get_post('product_id');
$data = array();
if (empty($affiliate_id)
&& empty($product_id))
{
$this->session->set_flashdata('error', 'Please enter an affiliate ID, a product ID, or both.');
redirect('admin/affiliate_relationship');
}
if (empty($affiliate_id))
{
$data['affiliate_relationship'] = $this->AffiliateRelationship->search_for_affiliate_by_product_id($product_id);
}
elseif (empty($product_id))
{
$data['affiliate_relationship'] = $this->AffiliateRelationship->search_for_affiliate_by_affiliate_id($affiliate_id);
$affiliate = $affiliate_id;
}
elseif (!empty($affiliate_id)
&& !empty($product_id))
{
$data['affiliate_relationship'] = $this->AffiliateRelationship->search_for_affiliate($affiliate_id, $product_id);
$affiliate = $affiliate_id . '/';
}
$data['affiliate_id'] = $affiliate_id;
$data['product_id'] = $product_id;
redirect_and_continue_processing('admin/affiliate_relationship/' . $affiliate . $product_id, $data);
When I pr($data) I get the array correctly, so I know the data is all there. It's just when it is used in the view it does not even exist.
Am I doing something wrong? I've done other controller and views more-or-less the same way and never got problem this before.
EDIT: View code.
<?php
$affiliateRelationshipRows = NULL;
if (!empty($affiliate_relationship))
{
$class = NULL;
$i = 0;
foreach ($affiliate_relationship->result_array() as $affiliate)
{
if (++$i%2 == 0)
{
$class= ' class="odd"';
}
else
{
$class = NULL;
}
$affiliateRelationshipRows .= <<<END
<tr $class>
<td class="text-left">{$affiliate['id']}</td>
<td class="text-left">{$affiliate['product_id']}</td>
<td class="text-left">{$affiliate['user_id']}</td>
<td class="text-left">{$affiliate['affiliate_status_id']}</td>
<td class="text-left">{$affiliate['created']}</tD>
<td class="text-left">{$affiliate['custom_payout']}</td>
<td class="text-left">{$affiliate['delayed']}</td>
<td class="text-left">{$affiliate['sales_page_url']}</td>
<td class="text-left">{$affiliate['comments']}</td>
</tr>
END;
}
}
?>
<?php echo form_open($this->uri->uri_string()); ?>
<div class="box-search">
<div class="grid-2" style="width:200px; margin-left:25px;">
<span class="label" style="float:none;">
Affiliate ID:
</span>
<span class="field" style="float:none;">
<input type="text" name="affiliate_id" value="<?php if (!empty($affiliate_id)) { echo $affiliate_id; } ?>" style="width: 75px;"/>
</span>
<?php echo form_error('affiliate_id'); ?>
</div>
<div class="grid-2" style="width:200px; margin-left:0px;">
<span class="label" style="float:none; ">
Product ID:
</span>
<span class="field" style="float:none;">
<input type="text" name="product_id" value="<?php if (!empty($product_id)) { echo $product_id; } ?>" style="width:75px;"/>
</span>
<?php echo form_error('product_id'); ?>
</div>
RESET
<input type="submit" name="search" class="btn btn-green btn-mini-submit btn-search" value="SEARCH"/>
<div class="clear"></div>
</div>
<?php echo form_close(); ?>
<div class="box">
<div class="top">
Affiliate Relationship
</div>
<div class="main-table">
<table class="style1" cellpadding="2" cellspacing="0" width="100%" border="0">
<thead>
<tr>
<th>ID</th>
<th>Product ID</th>
<th>User ID</th>
<th>Affiliate Status ID</th>
<th>Created</th>
<th>Custom Payout</th>
<th>Delayed</th>
<th>Sales Page URL</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<?php echo $affiliateRelationshipRows; ?>
</tbody>
</table>
</div>
The array:
Array
(
[affiliate_relationship] => Array
(
[0] => stdClass Object
(
[id] => 11615304
[created] => 2015-09-17 00:00:00
[product_id] => 175538
[user_id] => 393598
[comments] =>
[affiliate_status_id] => 2
[custom_payout] =>
[delayed] => 0
[sales_page_url] =>
)
)
[affiliate_id] => 11615304
[product_id] => 175538
)
I don't think you can send data like that in redirect_and_continue_processing() or redirect() in codeigniter. The only way to do that is by sending the data as an argument to the function that you are trying to redirect to. Then in that function, use the data to generate the view.
LIke :
redirect_and_continue_processing('admin/affiliate_relationship/' . $affiliate . $product_id/$data);
And in the method "affiliate_relationship" , accept the argument
Redirect method does not take an argument as the variable to send to view.
instead of using
redirect_and_continue_processing('admin/affiliate_relationship/' . $affiliate . $product_id, $data);
you can use simple way to do this
$this->load->view('your_view_name','your data in array');

Update multiple rows with where clause in codeigniter

I have a list of records from database, see the attachment. How can i insert a vat no for each record using student id(see leftmost column). Each record has a input field(see rightmost column).
Here is my view:
<?php $attributes = array('id' => 'VATformAdd', 'name' =>
'VATformAdd', 'autocomplete' => 'off'); echo form_open('report/addVATno', $attributes);?>
<fieldset>
<legend>Income By Student Admission</legend>
<table class="">
<thead>
<tr>
<th width="15%">Student ID</th>
<th width="15%">Student Form No</th>
<th width="15%">Course</th>
<th width="20%">Student Name</th>
<th width="15%">Admitted by</th>
<th width="10%">Amount</th>
<th width="10%">VAT Serial No</th>
</tr>
</thead>
<tbody>
<?php
if (isset($addmission_income)) {
foreach ($addmission_income as $addmissionincome) {
?>
<tr>
<td><?php echo $addmissionincome->student_id;?></td>
<td><?php echo $addmissionincome->student_form_no;?></td>
<td><?php echo $addmissionincome->course_name;?></td>
<td><?php echo $addmissionincome->student_full_name;?></td>
<td><?php echo user_profile_name($addmissionincome->student_added_by); ?></td>
<td><?php echo $addmissionincome->student_fee_paid;?></td>
<td><input type="text" name="vatno[<?php echo $addmissionincome->student_id;?>]" class="width-100"/></td>
<?php
}
?>
</tr>
<?php
}
?>
</tbody>
</table>
<p>
<input id="submit" name="submit" type="submit" value="Add VAT Number" />
</p>
</fieldset>
<?php echo form_close();?>
Here is my controller:
function addVATno(){
$studentid = $this->input->post('studentid');
foreach($studentid as $a){
if($val[$a]!=''){
$this->report_mdl->addVATno($a);
}
}
}
Here is Model:
function addVATno($a){
$val = $this->input->post('vatno');
$updatevatsl = array(
'dupVATserial_no' => $val);
$this->db->where('student_id', $a);
$query = $this->db->update('data_student_master', $updatevatsl);
return $query;
}
make your view file with a hidden student_id like:
<input type="hidden" name="student_id[]" value="<?php echo $addmissionincome->student_id;?>"/>
and vatno field:
<input type="text" name="vatno[]" class="width-100"/>
Adding the following to your controller will do everything you need (without needing to put any code in your model):
$student_id = $this->input->post('student_id');
$vatno = $this->input->post('vatno');
for ($i = 0; $i < count($student_id); $i++) {
$sm_data[] = array(
'vatno' => $vatno[$i],
'student_id' => $student_id[$i]
);
}
$this->db->update_batch('data_student_master', $sm_data, 'student_id');
Note: It would be better to move the db call to your model to adhere to MVC conventions.
Your issue is that you aren't pulling the correct values from POST.
You are not submitting the student id on its own anywhere in the form, so I can't see how you would be able to access it from POST.
You are also trying to access 'vatno' from POST to insert it into a DB, but 'vatno' in POST is an array.
Because you are using the student id as the array key in your form, you can access both the student ID and the vat number you want to update from the same array. In your controller, you can do:
function addVATno(){
//vatnos is an array, the key is the student id
$vatnos = $this->input->post('vatno');
foreach($vatnos as $key=>$vatno){
$this->report_mdl->addVATno($key, $vatno);
}
}
Then in your model, you just need:
function addVATno($studentid, $vatno){
$updatevatsl = array(
'dupVATserial_no' => $vatno
);
$this->db->where('student_id', $studentid);
$query = $this->db->update('data_student_master', $updatevatsl);
return $query;
}

Display only specific array elements in a foreach loop

I have a page that contains an ordering form, on this form it lists the vendor information and then each of the products for the vendor underneath and in front of the product is an input field that allows the user to input the quantity of each product that they want.
Upon submitting the information goes to a confirmation page where I need to be able to show the order information. On the form on the order page, I have a hidden field that contains the vendor id. and the vendor id is put once for each vendor. What I need to be able to do is not only echo out the quantity but also echo out the vendor id specific for each order. My code is below. The first block is the order page and then the block below that will be the confirm page.
As it stands right now underneath every quantity it displays all the vendor ids as opposed to just the one I need.
<?php defined('C5_EXECUTE') or die("Access Denied.");?>
<div class="ccm-ui">
<?php
$db= Loader::db(); //This loads the database helper.
Loader::model('user'); //This loads the user Model.
$user = new User();
$userInfo = UserInfo::getByID($user->getUserID()); //This gets the user info for the current user.
$userCostCenter = $userInfo->getAttribute('cost_center'); //This sets a variable equal to the attribute Cost Center for the current user.
//The if statement below checks if the user is an admin and then displays the info accordingly.
if ($userCostCenter === "Admin") {
?>
<form name="SelectCostCenter" action="/adminorder" method="POST">
<select name="CostCenter">
<option value="unitedilluminating">United Illumination</option>
<option value="clp">CL&P</option>
</select>
<input type="submit" value="Continue">
<button style="float:right;" type="button" class="btn btn-primary"></button>
</form>
<?php
} elseif ($userCostCenter === "United Illuminating") {
?>
<form name="OrderForm" action="/confirm" method="POST">
<?php
$query = 'SELECT * FROM Vendors WHERE costCenterID = 1';
$productQuery = 'SELECT * FROM Products WHERE costCenterID = 1';
$results = $db->getAll($query);
$productResults = $db->getAll($productQuery);?>
<table class="table">
<thead>
<tr>
<th>Quantity/Product</th>
<th>Category</th>
<th>Vendor</th>
<th>Address</th>
</tr>
<?php
foreach ($results as $vendor) {
?>
<tr class="category">
<td></td>
<td><?php echo $vendor['Category']; ?></td>
<td><?php echo $vendor['Vendor']; ?></td>
<td><?php echo $vendor['Address']; ?></td>
</tr>
<?php foreach ($productResults as $product) { ?>
<tr class="product">
<td colspan="4"><span class="name"><input type="text" name="quantities[]" size="1" /><?php echo $product['Product'];?></span></td>
</tr>
<?php } ?>
<td><input type="hidden" name="vendor[]" value="<?php echo $vendor['vendorID']; ?>"/></td>
<?php
}?>
</table>
<input type="submit" value="Checkout"<button style="float:right;" type="button" class="btn btn-primary"></button>
</form>
</div><?php
}
else {
?>
<form name="OrderForm" action="/confirm" method="POST">
<?php $query = 'SELECT * FROM Vendors Where costCenterID = 2';
$productquery = 'SELECT * FROM Products WHERE costCenterID = 2';
$results = $db->getAll($query);
$productresults = $db->getAll($productquery);?>
<table class="table">
<thead>
<tr>
<th>Quantity/Product</th>
<th>Category</th>
<th>Vendor</th>
<th>Address</th>
</tr>
<?php
foreach ($results as $vendor) {
?>
<tr class="category">
<td></td>
<td><?php echo $vendor['Category'];?></td>
<td><?php echo $vendor['Vendor'];?> </td>
<td><?php echo $vendor['Address'];?></td>
</tr>
<?php
foreach ($productresults as $product){
?>
<tr class="product">
<td colspan="4"><span class="name"><input type="text" name="quantities[<?php echo $vendor['vendorID']; ?>]" size="1" /><?php echo $product['Product'];?></span></td>
<td><input type="hidden" name="vendor[]" value="<?php echo $vendor['vendorID']; ?>"/></td>
</tr>
<?php
}
?>
<?php
}?>
</table>
<input type="submit" value="Checkout"<button style="float:right;" type="button" class="btn btn-primary"></button>
</form>
</div><?php
}
?>
This is the confirm page below.
<?php defined('C5_EXECUTE') or die("Access Denied.");
$db= Loader::db();
$quantity = $_POST['quantities'];
$vendor = $_POST['vendor'];
$minimumorder = 25;
foreach($quantity as $num){
if ($num >= $minimumorder){
echo "$num";
echo "</br>";
foreach($vendor as $vendors){
echo "$vendors";
echo "</br>";
}
}
}
?>
I appreciate any help anyone can give. This has had me stumped for a few days actually.
you might want to rearrange your array, and do something like:
$i = 0;
foreach ($productresults as $product) {
echo '<input name="product['.$i.'][quantity]" />';
echo '<input name="product['.$i.'][vendor_id]" value="'.$vendor['vendorID'].'" type="hidden" />';
++$i;
}
The resulting array in $_POST would have the quantities & their vendor separated into their own arrays.
In your code $vendor['vendorID'] seems the key of your $_POST['quantities'] so in your confirm page you could use:
foreach($quantity as $vendorid=>$num){
if ($num >= $minimumorder){
echo "$num";
echo "</br>";
echo "$vendorid";
}
}

Categories