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 261013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:23:47+00:00 2026-05-11T22:23:47+00:00

i am trying to figure out how to create a javascript alert box asking

  • 0

i am trying to figure out how to create a javascript alert box asking the user if they would like to delete a record (that their viewing) and when the user presses yes a query is called through php to delete a database row. and if the user presses no nothing will happend.

wondering how this can be done

thanks

ps:

this is what i did and it didnt work.

<script type="text/javascript">
if(window.confirm("Are you sure you want to delete that record?")) { 
<?php
mysql_query("delete from tbl_payments where id = '$id'") or die(mysql_error());
header("Location: dashboard.php");
?>
}
</script>
  • 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-05-11T22:23:47+00:00Added an answer on May 11, 2026 at 10:23 pm
    if (window.confirm("Are you sure?")) {
      // call php code here, either through going to a new page,
      // or by doing an ajax request
    }
    

    For your update: The problem is that the PHP code is being executed by the server, which does not run the Javascript, and the Javascript runs at the client side, with no knowledge of the PHP code.

    This means the PHP code will always run, simply ignoring the the window.prompt call, as that is not part of PHP. The Javascript that is executed by the client looks simply like this:

    <script type="text/javascript">
    if(window.confirm("Are you sure you want to delete that record?")) { 
    }
    </script>
    

    Which obviously does nothing, if you were to even reach this page, because you are sending the user to a new page using the Location header.

    What you need to do is put the PHP code you wrote on a second page, and take the client to that page, only once the window.confirm() has run. Something like this:

    file1.php

    <script type="text/javascript">
    if(window.confirm("Are you sure you want to delete that record?")) {
      document.location = "file2.php?id=<?php echo $_GET['id'] ?>";
    }
    </script>
    

    file2.php

    <?php
    $id = $_GET['id'];
    if (!is_numeric($id)) $id = -1;
    mysql_query("delete from tbl_payments where id = '$id'") or die(mysql_error());
    header("Location: dashboard.php");
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 217k
  • Answers 217k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No, all three have external linkage. Member functions of a… May 12, 2026 at 11:17 pm
  • Editorial Team
    Editorial Team added an answer You could automatically post the second form using JavaScript: <script>document.forms[0].submit()</script>… May 12, 2026 at 11:17 pm
  • Editorial Team
    Editorial Team added an answer It ensures uniqueness across disconnected systems. Any data store which… May 12, 2026 at 11:17 pm

Related Questions

I am trying to figure out how to get the program to create a
A little advise please. I am trying to create a tree out of following
I am trying to create a custom CStatic control in vc++ and have a
I would like to create a very simple image gallery. I am trying to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.