Page 1 of 1
Simple Stock Update
Posted: Sun May 01, 2022 12:47 pm
by tessthepup
I have been working on a simple stock update page.
The page retrieves & displays the data ok but I am having trouble posting the updated values back to the database.
I don't think I am far off if someone could take a look for me.
If you are going to use it when working then you will need s02e08 Products Cost addon as well.
Thanks
Re: Simple Stock Update
Posted: Sun May 01, 2022 5:07 pm
by ecartz
Code: Select all
require 'includes/application_top.php';
if ('update' === $_POST['update']) {
foreach ($_POST['model'] as $product_id => $model) {
$sql_data = [
'products_model' => $model,
'products_cost' => $_POST['cost'][$product_id],
'products_price' => $_POST['price'][$product_id],
'products_weight' => $_POST['weight'][$product_id],
'products_quantity' => $_POST['qty'][$product_id],
];
$db->perform('products', $sql_data, 'update', 'products_id = ' . (int)$product_id);
}
Href::redirect($Admin->link('stock_update.php', ['update' => 'Success', 'product_update' => $_POST['product_update']));
}
require 'includes/template_top.php';
and
Code: Select all
<tr>
<td class="text-left"><?= $products_name=$product['products_name'] ?></td>
<td class="text-center"><input type="text" name="model[<?= $product['products_id'] ?>]"value="<?= $product['products_model'] ?>" size="8"></td>
<td class="text-center"><input type="text" name="cost[<?= $product['products_id'] ?>]" value="<?= $currencies->format_raw($product['products_cost']) ?>" size="4"></td>
<td class="text-center"><input type="text" name="price[<?= $product['products_id'] ?>]" value="<?= $currencies->format_raw($product['products_price']) ?>" size="4"></td>
<td class="text-center"><input type="text" name="weight[<?= $product['products_id'] ?>]" value="<?= $product['products_weight'] ?>" size="4"></td>
<td class="text-center"><input type="text" name="qty[<?= $product['products_id'] ?>]" value="<?= $product['products_quantity'] ?>" size="3"></td>
</tr>
Re: Simple Stock Update
Posted: Mon May 02, 2022 7:52 am
by tessthepup
ecartz wrote: ↑Sun May 01, 2022 5:07 pm
Code: Select all
require 'includes/application_top.php';
if ('update' === $_POST['update']) {
foreach ($_POST['model'] as $product_id => $model) {
$sql_data = [
'products_model' => $model,
'products_cost' => $_POST['cost'][$product_id],
'products_price' => $_POST['price'][$product_id],
'products_weight' => $_POST['weight'][$product_id],
'products_quantity' => $_POST['qty'][$product_id],
];
$db->perform('products', $sql_data, 'update', 'products_id = ' . (int)$product_id);
}
Href::redirect($Admin->link('stock_update.php', ['update' => 'Success', 'product_update' => $_POST['product_update']));
}
require 'includes/template_top.php';
and
Code: Select all
<tr>
<td class="text-left"><?= $products_name=$product['products_name'] ?></td>
<td class="text-center"><input type="text" name="model[<?= $product['products_id'] ?>]"value="<?= $product['products_model'] ?>" size="8"></td>
<td class="text-center"><input type="text" name="cost[<?= $product['products_id'] ?>]" value="<?= $currencies->format_raw($product['products_cost']) ?>" size="4"></td>
<td class="text-center"><input type="text" name="price[<?= $product['products_id'] ?>]" value="<?= $currencies->format_raw($product['products_price']) ?>" size="4"></td>
<td class="text-center"><input type="text" name="weight[<?= $product['products_id'] ?>]" value="<?= $product['products_weight'] ?>" size="4"></td>
<td class="text-center"><input type="text" name="qty[<?= $product['products_id'] ?>]" value="<?= $product['products_quantity'] ?>" size="3"></td>
</tr>
Than you very much for the rewrite however I get a white screen.
If I comment out this line the page shows but does not work (obvs)
Code: Select all
Href::redirect($Admin->link('stock_update.php', ['update' => 'Success', 'product_update' => $_POST['product_update']));
Re: Simple Stock Update
Posted: Wed May 04, 2022 5:50 pm
by tessthepup
I finally got a minute over a brew to have another look and as far as I can see this line was missing a closing ]
Code: Select all
Href::redirect($Admin->link('stock_update.php', ['update' => 'Success', 'product_update' => $_POST['product_update']]));
The white screen of death has gone now and the page loads however still does not update values in the dbase.
This error is now showing for the following lines of code
PHP Notice: Undefined index
Code: Select all
Line 5 - if ('update' === $_POST['update']) {
Line 25 - if ($_GET['product_update']!="") {
Line 46 - <?php if($_GET['update']=="Success"){?>
Line 80 - <input type="hidden" name="product_update" value="<?php echo $_POST['product_update']; ?>"><input type="submit" class="btn btn-success" name="update" value="Update">
Re: Simple Stock Update
Posted: Wed May 04, 2022 6:17 pm
by ecartz
Code: Select all
if (isset($_POST['update']) && ('update' === $_POST['update'])) {
So on and so forth.
Code: Select all
<?= $_POST['product_update'] ?? '' ?>
Re: Simple Stock Update
Posted: Wed May 25, 2022 11:07 am
by tessthepup
ecartz wrote: ↑Wed May 04, 2022 6:17 pm
Code: Select all
if (isset($_POST['update']) && ('update' === $_POST['update'])) {
So on and so forth.
Code: Select all
<?= $_POST['product_update'] ?? '' ?>
Feeling a little guilty for not getting back to this but I can not resolve the undefined index error on this line
Code: Select all
<?php if ($_GET['update']=="Success"){?>
Re: Simple Stock Update
Posted: Wed May 25, 2022 2:05 pm
by tessthepup
I have managed to clear the error but now the page does not update the values to the database and the success message does not display.
I have attached the full addon if anyone has time to tinker
Re: Simple Stock Update
Posted: Sun Aug 11, 2024 6:11 pm
by Dan Cole
I know this is a little dated, but I wonder if you ever got this working? I want to work up a simple routine to update the payment status for orders on my site and thought this might make for a good starting point.
Dan
Re: Simple Stock Update
Posted: Tue Aug 13, 2024 8:22 am
by burt
Dan Cole wrote: ↑Sun Aug 11, 2024 6:11 pm
I know this is a little dated, but I wonder if you ever got this working? I want to work up a simple routine to update the payment status for orders on my site and thought this might make for a good starting point.
Dan
I don't remember if the PRO code "batch actions" does this. I think it might.
app.php/tag/s05e01
Re: Simple Stock Update
Posted: Tue Aug 13, 2024 3:28 pm
by Dan Cole
burt wrote: ↑Tue Aug 13, 2024 8:22 am
I don't remember if the PRO code "batch actions" does this. I think it might.
app.php/tag/s05e01
It will update the order status but not the payment status, which is likely something I added over the years. You did however give me and idea and starting place.
Dan