I am trying to make an admin panel for my restaurant website. The system generates a user snippet(admin_panel_user_display_snippet
) for every user on the database and replaces the values with their places. I also added a form to delete the user from the database.
The form’s action gets replaced with the /delete-user-John"(let's say the user's name is John)
. When you get routed to the form’s action; the system deletes the user. But there is a mistake.
I cannot get redirected to /delete-user-John
. I get an error called
Cannot POST to /delete-user-john
What am I doing wrong?
var user_card_name_result;
var data_food_snippet_display_replaced = data.replace("#admin-panel-display-user-div-2{display: none;}", "#admin-panel-display-user-div-2{display: flex;}");
var admin_panel_user_display_snippet_12 = "";
var admin_panel_user_display_snippet = "<div id='admin-panel-display-user-div-2'><div id='admin-panel-display-user-name-div'><div id='admin-panel-display-user-name-header-div'><h1 id='admin-panel-display-user-name-header'>Name And Surname</h1></div><div id='admin-panel-display-user-name-info-div'><p id='admin-panel-display-user-name-info'>adminpanelusername</p></div></div><div id='admin-panel-display-user-email-div'><div id='admin-panel-display-user-email-header-div'><h1 id='admin-panel-display-user-email-header'>Email</h1></div><div id='admin-panel-display-user-email-info-div'><p id='admin-panel-display-user-email-info'>[email protected]</p></div></div><div id='admin-panel-display-user-password-div'><div id='admin-panel-display-user-password-header-div'><h1 id='admin-panel-display-user-password-header'>Password</h1></div><div id='admin-panel-display-user-password-info-div'><p id='admin-panel-display-user-password-info'>adminpanelpassword</p></div></div><div id='admin-panel-display-user-phone-div'><div id='admin-panel-display-user-phone-header-div'><h1 id='admin-panel-display-user-phone-header'>Phone Number</h1></div><div id='admin-panel-display-user-phone-header-div'><p id='admin-panel-display-user-phone-info'>adminpanelphone</p></div></div><div id='admin-panel-display-user-credit-card-div'><div id='admin-panel-display-user-credit-card-header-div'><h1 id='admin-panel-display-user-credit-card-header'>Credit Card</h1></div><div id='admin-panel-display-user-phone-header-div'><p id='admin-panel-display-user-phone-info'>adminpanelcreditcard</p></div></div><div id='admin-panel-display-user-cvc-div'><div id='admin-panel-display-user-cvc-header-div'><h1 id='admin-panel-display-user-cvc-header'>CVC</h1></div><div id='admin-panel-display-user-cvc-info-div'><p id='admin-panel-display-user-cvc-info'>adminpanelcvc</p></div></div><div id='admin-panel-display-user-address-div'><div id='admin-panel-display-user-address-header-div'><h1 id='admin-panel-display-user-address-header'>Address</h1></div><div id='admin-panel-display-user-address-info-div'><p id='admin-panel-display-user-address-info'>adminpaneladdress</p></div></div><div id='admin-panel-display-user-exp-div'><div id='admin-panel-display-user-exp-header-div'><h1 id='admin-panel-display-user-address-header'>Exp.</h1></div><div id='admin-panel-display-user-exp-info-div'><p id='admin-panel-display-user-address-info'>adminpanelexp</p></div></div><div id='admin-panel-display-user-card-name-div'><div id='admin-panel-display-user-card-name-header-div'><h1 id='admin-panel-display-user-card-name-header'>Card Name</h1></div><div id='admin-panel-display-user-card-name-info-div'><p id='admin-panel-display-user-card-name-info'>adminpanelcardname</p></div></div><div id='admin-panel-display-user-delete-user-div'><form action='/delete-user-usernametodeletecomeshere' method='post'><div id='admin-panel-display-user-delete-user-button-div'><button type='submit' id='admin-panel-display-user-delete-user-button'>X</button></div></form></div></div><div style='height: 1vw;'' id='s-div'></div>";
for (var i = 0; i < user_count; i++) {
console.log(user_name_result[i]);
var name = JSON.stringify(user_name_result[i]).slice(14, -2);
var email = JSON.stringify(user_email_result[i]).slice(15, -2);
var password = JSON.stringify(user_password_result[i]).slice(13, -2);
var phone = JSON.stringify(user_phone_result[i]).slice(15, -2);
var credit_card = JSON.stringify(user_credit_card_result[i]).slice(16, -2);
var cvc = JSON.stringify(user_cvc_result[i]).slice(8, -2);
var address = JSON.stringify(user_address_result[i]).slice(18, -2);
var exp = JSON.stringify(user_exp_result[i]).slice(13, -2);
var card_name = JSON.stringify(user_card_name_result[i]).slice(14, -2);
var admin_panel_user_display_snippet_2 = admin_panel_user_display_snippet.replace("adminpanelusername", name);
var admin_panel_user_display_snippet_3 = admin_panel_user_display_snippet_2.replace("[email protected]", email);
var admin_panel_user_display_snippet_4 = admin_panel_user_display_snippet_3.replace("adminpanelpassword", password);
var admin_panel_user_display_snippet_5 = admin_panel_user_display_snippet_4.replace("adminpanelphone", phone);
var admin_panel_user_display_snippet_6 = admin_panel_user_display_snippet_5.replace("adminpanelcreditcard", credit_card);
var admin_panel_user_display_snippet_7 = admin_panel_user_display_snippet_6.replace("adminpanelcvc", cvc);
var admin_panel_user_display_snippet_8 = admin_panel_user_display_snippet_7.replace("adminpaneladdress", address);
var admin_panel_user_display_snippet_9 = admin_panel_user_display_snippet_8.replace("adminpanelexp", exp);
var admin_panel_user_display_snippet_10 = admin_panel_user_display_snippet_9.replace("adminpanelcardname", card_name);
var admin_panel_user_display_snippet_11 = admin_panel_user_display_snippet_10.replace("usernametodeletecomeshere", name);
admin_panel_user_display_snippet_12 = admin_panel_user_display_snippet_12 + admin_panel_user_display_snippet_11;
app.post("/delete-user-" + name, function(req, res) {
console.log("delete_user_route", name);
});
}
var data_user_display_admin = data_food_snippet_display_replaced.replace(admin_panel_user_display_snippet, admin_panel_user_display_snippet_12);
res.write(data_user_display_admin);
res.end();
}
#admin-panel-display-user-div-2 {
width: 100%;
border: 2px solid #C94277;
display: flex;
justify-content: center;
align-items: center;
}
#admin-panel-display-user-name-div {
width: 10%;
}
#admin-panel-display-user-name-header-div {
width: 100%;
text-align: center;
}
#admin-panel-display-user-name-header {
font-family: sans-serif;
color: #C94277;
font-size: 0.7vw;
text-decoration: underline;
}
#admin-panel-display-user-name-info-div {
width: 100%;
text-align: center;
}
#admin-panel-display-user-name-info {
font-family: sans-serif;
color: gray;
font-size: 0.6vw;
}
#admin-panel-display-user-email-div {
width: 10%;
}
#admin-panel-display-user-email-header-div {
width: 100%;
text-align: center;
}
#admin-panel-display-user-email-header {
font-family: sans-serif;
color: #C94277;
font-size: 0.7vw;
text-decoration: underline;
}
#admin-panel-display-user-email-info-div {
width: 100%;
text-align: center;
}
#admin-panel-display-user-email-info {
font-family: sans-serif;
color: gray;
font-size: 0.6vw;
}
#admin-panel-display-user-password-div {
width: 10%;
}
#admin-panel-display-user-password-header-div {
width: 100%;
text-align: center;
}
#admin-panel-display-user-password-header {
font-family: sans-serif;
color: #C94277;
font-size: 0.7vw;
text-decoration: underline;
}
#admin-panel-display-user-password-info-div {
width: 100%;
text-align: center;
}
#admin-panel-display-user-password-info {
font-family: sans-serif;
color: gray;
font-size: 0.6vw;
}
#admin-panel-display-user-phone-div {
width: 10%;
}
#admin-panel-display-user-phone-header-div {
width: 100%;
text-align: center;
}
#admin-panel-display-user-phone-header {
font-family: sans-serif;
color: #C94277;
font-size: 0.7vw;
text-decoration: underline;
}
#admin-panel-display-user-phone-header {
font-family: sans-serif;
color: #C94277;
font-size: 0.7vw;
text-decoration: underline;
}
#admin-panel-display-user-phone-info {
font-family: sans-serif;
color: gray;
font-size: 0.6vw;
}
#admin-panel-display-user-credit-card-div {
width: 10%;
}
#admin-panel-display-user-credit-card-header-div {
width: 100%;
text-align: center;
}
#admin-panel-display-user-credit-card-header {
font-family: sans-serif;
color: #C94277;
font-size: 0.7vw;
text-decoration: underline;
}
#admin-panel-display-user-cvc-div {
width: 10%;
}
#admin-panel-display-user-cvc-header-div {
width: 100%;
text-align: center;
}
#admin-panel-display-user-cvc-header {
font-family: sans-serif;
color: #C94277;
font-size: 0.7vw;
text-decoration: underline;
}
#admin-panel-display-user-cvc-info-div {
width: 100%;
text-align: center;
}
#admin-panel-display-user-cvc-info {
font-family: sans-serif;
color: gray;
font-size: 0.6vw;
}
#admin-panel-display-user-address-div {
width: 10%;
}
#admin-panel-display-user-address-header-div {
width: 100%;
text-align: center;
}
#admin-panel-display-user-address-header {
font-family: sans-serif;
color: #C94277;
font-size: 0.7vw;
text-decoration: underline;
}
#admin-panel-display-user-address-info-div {
width: 100%;
text-align: center;
}
#admin-panel-display-user-address-info {
font-family: sans-serif;
color: gray;
font-size: 0.6vw;
}
#admin-panel-display-user-exp-div {
width: 10%;
}
#admin-panel-display-user-exp-header-div {
width: 100%;
text-align: center;
}
#admin-panel-display-user-exp-info-div {
width: 100%;
text-align: center;
}
#admin-panel-display-user-address-info {
font-family: sans-serif;
color: gray;
font-size: 0.6vw;
}
#admin-panel-display-user-card-name-div {
width: 10%;
}
#admin-panel-display-user-card-name-header {
font-family: sans-serif;
color: #C94277;
font-size: 0.7vw;
text-decoration: underline;
padding-left: 21%;
}
#admin-panel-display-user-card-name-info-div {
width: 100%;
text-align: center;
}
#admin-panel-display-user-card-name-info {
font-family: sans-serif;
color: gray;
font-size: 0.6vw;
}
#admin-panel-display-user-delete-user-div {
width: 10%;
}
#admin-panel-display-user-delete-user-button-div {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
#admin-panel-display-user-delete-user-button {
width: 1vw;
height: 1vw;
background-color: rgb(196, 35, 35);
color: white;
display: flex;
justify-content: center;
align-items: center;
border: 2px solid rgb(196, 35, 35);
}
<div id='admin-panel-display-user-div-2'>
<div id='admin-panel-display-user-name-div'>
<div id='admin-panel-display-user-name-header-div'>
<h1 id='admin-panel-display-user-name-header'>Name And Surname</h1>
</div>
<div id='admin-panel-display-user-name-info-div'>
<p id='admin-panel-display-user-name-info'>adminpanelusername</p>
</div>
</div>
<div id='admin-panel-display-user-email-div'>
<div id='admin-panel-display-user-email-header-div'>
<h1 id='admin-panel-display-user-email-header'>Email</h1>
</div>
<div id='admin-panel-display-user-email-info-div'>
<p id='admin-panel-display-user-email-info'>[email protected]</p>
</div>
</div>
<div id='admin-panel-display-user-password-div'>
<div id='admin-panel-display-user-password-header-div'>
<h1 id='admin-panel-display-user-password-header'>Password</h1>
</div>
<div id='admin-panel-display-user-password-info-div'>
<p id='admin-panel-display-user-password-info'>adminpanelpassword</p>
</div>
</div>
<div id='admin-panel-display-user-phone-div'>
<div id='admin-panel-display-user-phone-header-div'>
<h1 id='admin-panel-display-user-phone-header'>Phone Number</h1>
</div>
<div id='admin-panel-display-user-phone-header-div'>
<p id='admin-panel-display-user-phone-info'>adminpanelphone</p>
</div>
</div>
<div id='admin-panel-display-user-credit-card-div'>
<div id='admin-panel-display-user-credit-card-header-div'>
<h1 id='admin-panel-display-user-credit-card-header'>Credit Card</h1>
</div>
<div id='admin-panel-display-user-phone-header-div'>
<p id='admin-panel-display-user-phone-info'>adminpanelcreditcard</p>
</div>
</div>
<div id='admin-panel-display-user-cvc-div'>
<div id='admin-panel-display-user-cvc-header-div'>
<h1 id='admin-panel-display-user-cvc-header'>CVC</h1>
</div>
<div id='admin-panel-display-user-cvc-info-div'>
<p id='admin-panel-display-user-cvc-info'>adminpanelcvc</p>
</div>
</div>
<div id="admin-panel-display-user-address-div">
<div id='admin-panel-display-user-address-header-div'>
<h1 id='admin-panel-display-user-address-header'>Address</h1>
</div>
<div id='admin-panel-display-user-address-info-div'>
<p id="admin-panel-display-user-address-info">adminpaneladdress</p>
</div>
</div>
<div id='admin-panel-display-user-exp-div'>
<div id='admin-panel-display-user-exp-header-div'>
<h1 id='admin-panel-display-user-address-header'>Exp.</h1>
</div>
<div id='admin-panel-display-user-exp-info-div'>
<p id='admin-panel-display-user-address-info'>adminpanelexp</p>
</div>
</div>
<div id='admin-panel-display-user-card-name-div'>
<div id='admin-panel-display-user-card-name-header-div'>
<h1 id='admin-panel-display-user-card-name-header'>Card Name</h1>
</div>
<div id='admin-panel-display-user-card-name-info-div'>
<p id="admin-panel-display-user-card-name-info">adminpanelcardname</p>
</div>
</div>
<div id='admin-panel-display-user-delete-user-div'>
<form action='/delete-user-usernametodeletecomeshere' method='post'>
<div id='admin-panel-display-user-delete-user-button-div'><button type='submit' id='admin-panel-display-user-delete-user-button'>X</button></div>
</form>
</div>
</div>