Simple Stock Update
- tessthepup
- Certified Developer
- Posts: 383
- Joined: Mon Mar 01, 2021 5:55 pm
- Phoenix Version:
- Has thanked: 47 times
- Been thanked: 62 times
Simple Stock Update
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
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
You do not have the required permissions to view the files attached to this post.
Tags:
-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: Simple Stock Update
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';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>- tessthepup
- Certified Developer
- Posts: 383
- Joined: Mon Mar 01, 2021 5:55 pm
- Phoenix Version:
- Has thanked: 47 times
- Been thanked: 62 times
Re: Simple Stock Update
Than you very much for the rewrite however I get a white screen.ecartz wrote: ↑Sun May 01, 2022 5:07 pmandCode: 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';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>
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']));- tessthepup
- Certified Developer
- Posts: 383
- Joined: Mon Mar 01, 2021 5:55 pm
- Phoenix Version:
- Has thanked: 47 times
- Been thanked: 62 times
Re: Simple Stock Update
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 ]
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
Code: Select all
Href::redirect($Admin->link('stock_update.php', ['update' => 'Success', 'product_update' => $_POST['product_update']]));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">
-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: Simple Stock Update
Code: Select all
if (isset($_POST['update']) && ('update' === $_POST['update'])) {Code: Select all
<?= $_POST['product_update'] ?? '' ?>- tessthepup
- Certified Developer
- Posts: 383
- Joined: Mon Mar 01, 2021 5:55 pm
- Phoenix Version:
- Has thanked: 47 times
- Been thanked: 62 times
Re: Simple Stock Update
Feeling a little guilty for not getting back to this but I can not resolve the undefined index error on this lineecartz wrote: ↑Wed May 04, 2022 6:17 pmSo on and so forth.Code: Select all
if (isset($_POST['update']) && ('update' === $_POST['update'])) {Code: Select all
<?= $_POST['product_update'] ?? '' ?>
Code: Select all
<?php if ($_GET['update']=="Success"){?>- tessthepup
- Certified Developer
- Posts: 383
- Joined: Mon Mar 01, 2021 5:55 pm
- Phoenix Version:
- Has thanked: 47 times
- Been thanked: 62 times
Re: Simple Stock Update
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
I have attached the full addon if anyone has time to tinker
You do not have the required permissions to view the files attached to this post.
-
Dan Cole
- Senior Contributor
- Posts: 499
- Joined: Fri Oct 25, 2019 2:14 pm
- Phoenix Version: 1.0.8.21
- Has thanked: 67 times
- Been thanked: 61 times
Re: Simple Stock Update
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
Dan
- burt
- Core Team
- Posts: 4551
- Joined: Tue Oct 29, 2019 9:37 am
- Phoenix Version: v1.1.0.8
- : Buy Me A Beverage
- Has thanked: 252 times
- Been thanked: 412 times
Re: Simple Stock Update
I am not here to build for you.
I am here to build with you. Let's help each other.
I am here to build with you. Let's help each other.
-
Dan Cole
- Senior Contributor
- Posts: 499
- Joined: Fri Oct 25, 2019 2:14 pm
- Phoenix Version: 1.0.8.21
- Has thanked: 67 times
- Been thanked: 61 times
Re: Simple Stock Update
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.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
Dan