Pop-up message after submitting a form with php

Bruno Reis

I'm trying to get a pop-up message saying if it was successfully submitted or not without having to go to a different page.

Now chrome gives me the pop-up message but it redirects me to a blank page after.

Here is my current code.

<?php
include "header.php";
include "conexao.php";
echo "<h1 align='center'>Pagina para alterar produtos</h1><div class='container'><hr>";
$referencia=$_GET['id'];


$sql = "SELECT * ";
        $sql = $sql . " FROM tb_produto ";
        $sql = $sql . " WHERE pr_codigo='".$referencia."'";
        $produtos = $db->query($sql);
        foreach ($produtos as $produto) {
            $referencia = $produto["pr_codigo"];
            $nome = $produto["pr_descricao"];
            $preco = $produto["pr_preco"];
            $disponivel = $produto["disponivel"];
        }
        echo "<h2>Referencia: ".$referencia."</h2>";
        echo "<h2>Nome: ".$nome."</h2><hr>";

?>
<form action="confirmaAlterar.php">
<div class="form-group">
<label>Referencia</label>
    <input class="form-control" type="text" name="referencia" value="<?php echo $referencia?>">
</div>
<div class="form-group">
<label>Nome</label>
    <input class="form-control" type="text" name="nome" value="<?php echo $nome?>">
</div>
<div class="form-group">
<label>Preço</label>
    <input class="form-control" type="text" name="preco" value="<?php echo $preco?>">
</div>
<button class="btn btn-primary">Alterar</button>
</form>

Here is where it submits the information of the form.

<?php
include "header.php";
include "conexao.php";
$nome=$_GET['nome'];
$referencia=$_GET['referencia'];
$preco=$_GET['preco'];
$sql="UPDATE tb_produto SET pr_descricao='".$nome;
$sql.="', pr_preco=".$preco;
$sql.= " WHERE pr_codigo='".$
try{
    $comando=$db->prepare($sql);
    $comando->execute();
    echo "<script type='text/javascript'>alert('submitted successfully!')</script>";
    header( "refresh2;Location:index.php" );
}
catch (PDOException $e){
    echo "A";
}
Stefan Michelangelo Mihajlovic

To pass values using ajax. Form:

<form id="form">
<input type="text" value="test" name="akcija"> 
</form>

All inputs fields values in your form will be passed.

Ajax:

jQuery(function(){
$('#form').on('submit', function (e) { //on submit function
    e.preventDefault();
    $.ajax({
      type: 'post', //method POST
      url: 'yoururl.php', //URL of page where u place query and passing values
      data: $('#form').serialize(), //seriallize is passing all inputs values of form
      success: function(){ //on success function
              $("#input").attr("disabled", true); //example
              $("#input").removeClass('btn-primary').addClass('btn-success');//example
                  },
    });
}
});

And on the ajax page you can get values by

$akcija = $_POST['akcija']

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Django pop up message (modal) after the user updating form

How to get the sucess message in the same page after submitting the contact form?

Where form fields data are stored after submitting a FORM in PHP?

Javascript activate pop up after form validation

How to make pop up show up after the fields of the form are fulfilled?

Form clears after submitting

form in php not redirecting to page after submitting

Trying to redirect in PHP after submitting an email form

I have a blank page after submitting a php mysqli update form,

php - How to keep form values after submitting to another website?

How to add message after submitting form? PHP, Wordpress

How to redirect after submitting form in php

display error message after submitting a form

After submitting a login form, URL remains on the action php

I want to pop up a div after submit a form

Display custom message after submitting a Google Form

How to display alert message after submitting form

Form not submitting after form validation

How to add a success message after submitting Word form?

PHP - $_POST variable is not set after form submitting

PHP variables not showing up after submitting form (closed)

Not able to display message after submitting form using ajax

Show pop up after submit form

Not able to close modal pop up window after form submission

How to get the success message in the same page after submitting the form?

React displaying message after submitting the form

How to load table data after submitting the form in react js php

After submitting form its showing success message on different page

PHP add form refreshes after submitting but doesn't insert into database

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  3. 3

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    Do Idle Snowflake Connections Use Cloud Services Credits?

  9. 9

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  10. 10

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  11. 11

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  12. 12

    Generate random UUIDv4 with Elm

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  17. 17

    EXCEL: Find sum of values in one column with criteria from other column

  18. 18

    Pandas - check if dataframe has negative value in any column

  19. 19

    How to use merge windows unallocated space into Ubuntu using GParted?

  20. 20

    Make a B+ Tree concurrent thread safe

  21. 21

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

HotTag

Archive