Gitlab@Informatics
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cloudupdate_prj
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
65160270
cloudupdate_prj
Commits
ea31277f
Commit
ea31277f
authored
2 months ago
by
65160270
Browse files
Options
Downloads
Patches
Plain Diff
update-cart
parent
4c727541
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
shop-routes/product.js
+16
-0
16 additions, 0 deletions
shop-routes/product.js
views/index.ejs
+7
-1
7 additions, 1 deletion
views/index.ejs
views/product.ejs
+7
-0
7 additions, 0 deletions
views/product.ejs
with
30 additions
and
1 deletion
shop-routes/product.js
+
16
−
0
View file @
ea31277f
...
...
@@ -111,5 +111,21 @@ router.post("/edit/:id", upload.single("image"), async (req, res) => {
}
});
// ลบสินค้า
router
.
post
(
"
/delete/:id
"
,
async
(
req
,
res
)
=>
{
try
{
const
productId
=
req
.
params
.
id
;
// ลบสินค้าออกจากฐานข้อมูล
await
pool
.
execute
(
"
DELETE FROM products WHERE id = ?
"
,
[
productId
]);
console
.
log
(
"
Product deleted successfully!
"
);
res
.
redirect
(
"
/products
"
);
// กลับไปยังหน้ารายการสินค้า
}
catch
(
error
)
{
console
.
error
(
"
Error deleting product:
"
,
error
);
res
.
status
(
500
).
send
(
"
Error deleting product.
"
);
}
});
module
.
exports
=
router
;
This diff is collapsed.
Click to expand it.
views/index.ejs
+
7
−
1
View file @
ea31277f
...
...
@@ -20,7 +20,13 @@
<button type="submit">Add to Cart</button>
</form>
<td>
<a href="/products/edit/<%= product.id %>">Edit</a> <!-- Edit button -->
<a href="/products/edit/<%= product.id %>">Edit</a>
<form action="/products/delete/<%= product.id %>" method="POST" style="display: inline;">
<button type="submit" onclick="return confirm('Are you sure you want to delete this product?')">
Delete
</button>
</form>
</td>
</div>
<% }); %>
...
...
This diff is collapsed.
Click to expand it.
views/product.ejs
+
7
−
0
View file @
ea31277f
...
...
@@ -22,6 +22,13 @@
<td><
%=
product.price
%
>
THB
</td>
<td><
%=
product.stock
%
></td>
<td><
%=
product.description
%
></td>
<td>
<form
action=
"/products/delete/<%= product.id %>"
method=
"POST"
style=
"display:inline;"
>
<button
type=
"submit"
onclick=
"return confirm('Are you sure you want to delete this product?')"
>
Delete
</button>
</form>
</td>
</tr>
<
%
});
%
>
</table>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment