Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9116567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:42:21+00:00 2026-06-17T04:42:21+00:00

In this code, when user adds delete button, raw is being deleted from database,

  • 0

In this code, when user adds delete button, raw is being deleted from database, but user is being redirected to empty home page, unless he logs out and logs in again. how can I fix the code, so that when he deletes something, whole layout is not disappearing, but only the line that he deleted.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>




<script type="text/javascript">

function del() {
    if (confirm("Do You Want to Delete this Menu?")) {
    } else {
        return false;
    }
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" href="images/style.css" type="text/css"
charset="utf-8" />
</head>
<body>
<%

    menu_slno1 = request.getParameter("menu_slno");
    if (menu_slno1 != null)
        menu_slno = Integer.parseInt(menu_slno1);
    delete_menu = request.getParameter("delete_menu");


    if ("yes".equals(delete_menu)) {
        MenuId = request.getParameter("MenuId");
        x = stmt1
                .executeUpdate("Delete from menu where MenuId="
                        + MenuId);
    }
%>


<center><h2>VIEW MENU</h2></center>

<center><table width="736" height="97" border="1"></center>
    <%
        if (x == 1) {
    %>
    <tr bgcolor="gray">
        <th height="35" colspan="9"><div align="center">
                Menu deleted successfully!
            </div></th>
    </tr>
    <%
        }
    %>
    <tr bgcolor="gray">
        <td><div align="center">
                <strong>Menu ID</strong>
            </div></td>
        <td><div align="center">
                <strong>Name </strong>
            </div></td>
        <td><div align="center">
                <strong>Info</strong>
            </div></td>
        <td><div align="center">
                <strong>Price</strong>
            </div></td>
        <td colspan="2"><div align="center">
                <strong>Action</strong>
            </div></td>
    </tr>
    <%

     String sUserID=request.getParameter("username");
      session.setAttribute("username", sUserID);
        int icount = 0;
        rs = stmt.executeQuery("SELECT menu.menuID, menu.name, menu.info, menu.price, menu.RestaurantID  FROM menu INNER JOIN clients ON menu.username = clients.username where menu.username='" +sUserID+ "'");

        while (rs.next()) {
            //menu_slno = rs.getInt("menu_slno");
            MenuId = rs.getString("MenuId");
        %>
    <tr>
        <td><div align="center"><%=++icount%></div></td>

        <td><%=rs.getString("Name")%></td>
        <td><%=rs.getString("Info")%></td>
        <td><%=rs.getDouble("Price")%></td>

        <td><div align="center">
                <a href="edit_menu.jsp?MenuId=<%=MenuId%>">Edit</a>
            </div></td>
        <td><div align="center">
                <a
                    href="view_menu.jsp?delete_menu=yes&MenuId=    <%=MenuId%>&MenuId=<%=MenuId%>"
                    onclick="return del()">Delete</a>
            </div></td>
    </tr>
    <%
        }
    %>
</table>
<a href="add_menu.jsp">Add Menu</a>

</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:42:22+00:00Added an answer on June 17, 2026 at 4:42 am

    When a user clicks on the delete link, the username parameter is not set in the URL. So when the page refreshes, the String sUserID=request.getParameter("username"); call return null or empty, and then the rest of the page is not displayed because the following SQL Query returns nothing without a valid username.

    It seems that you only need to add something like &username=<%=sUserID%> to your delete link to make it work:

    <a href="view_menu.jsp?delete_menu=yes&MenuId=<%=MenuId%>&username=<%=sUserID%>" onclick="return del()">Delete</a>
    

    P.S: I assume that this a legacy JSP, and that you have no choice but continuing using such ugly code. If you have a choice, I strongly recommend you to drop those scriptlets and this all-in-the-view architecture, and start using JSTL tags, servlets and beans.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I execute this code the user is correct but the pass is not,
Now i'm using this code: User has_one User_extra User => :username, :email, :crypted_password, :salt,
I have a label and this code: string User = Environment.UserName; toolStripStatusLabel1.Text = This
This code $html = file_get_html('http://runkeeper.com/user/'.RUNKEEPER_ID.'/activity/'); $link1 = $html->find('.activityMonth', 0); will return the FIRST (foo,
I tried with this code to post on the wall (Twitter) of a user
I have written this code what it does is if user types postcode or
I'm wondering why this code section prints out the following: print request.user.has_perm('bug_tracking.is_developer'): + str(request.user.has_perm('bug_tracking.is_developer'))
I'm trying to empty a textarea that is populated from a database with php.
I have this code applied to a input test type onClick=this.value+='http://' , but I
This is a validation script This code runs when the user presses the submit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.