Gopal Joshi
Gopal Joshi

Reputation: 2358

How to create notification Message after Saving Record

I am trying to create Notification Message like "RECORD SUCCESSFULLY INSERTED" After Updating or Inserting Record In mydql table.

I have Code as below

if(isset($_GET['submit'])){
   if ($stmt = $mysqli->prepare("UPDATE fin_year SET year = ?, remark=? WHERE ent_no=?"))
   {
      $stmt->bind_param("ssi", $year, $remark, $ent_no);
      $stmt->execute();
      $stmt->close();
  }

 // show an error message if the query has an error
  else
  {
    echo "ERROR: could not prepare SQL statement.";
  }
}

have You any Idea For Notification Message..

Upvotes: 1

Views: 2531

Answers (4)

Anna Gabrielyan
Anna Gabrielyan

Reputation: 2170

if u don't want to use AJAX , just check if the query is successfully done and put notification message into temporary parameter and pass it back to view

 $stmt->bind_param("ssi", $year, $remark, $ent_no);
      $stmt->execute();
$success=  $mysqli->affected_rows; 
if($success>0){
   echo "success";//or something like this
}else
  {
    echo "ERROR: could not prepare SQL statement.";
  }

      $stmt->close();

Upvotes: 2

The Alpha
The Alpha

Reputation: 146201

You are doing it wrong, try this

$stmt = $mysqli->prepare("UPDATE fin_year SET year = ?, remark=? WHERE ent_no=?");
$stmt->bind_param("ssi", $year, $remark, $ent_no);
if($stmt->execute()) { // returns a boolean true on success, false on failure
    echo 'RECORD SUCCESSFULLY INSERTED';
}
else {
    echo 'ERROR OCCURRED!';
}
$stmt->close();

Upvotes: 0

Dalım Çepiç
Dalım Çepiç

Reputation: 513

Try this code (Notification with JS - Alert).

    <?php
    if(isset($_GET['submit'])){
       if ($stmt = $mysqli->prepare("UPDATE fin_year SET year = ?, remark=? WHERE ent_no=?"))
       {
          $stmt->bind_param("ssi", $year, $remark, $ent_no);
          $stmt->execute();
          $stmt->close();
      }
    ?>
     // show an error message if the query has an error

    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <?php


          else
          {
            echo "<script>alert('ERROR: could not prepare SQL statement.')</script>";
          }// if 2
        }// if 1
        ?>

    </head>
    <body>

    </body>
    </html>

if you want you can use your own POP-UP like Fancy to show the notification.

Upvotes: 1

Lance
Lance

Reputation: 4820

If the PHP that you've written above is being called on via Query's AJAX function, then you're going to need to generate that message via jQuery too. There's a success callback that's applicable to the AJAX function

$.ajax({  
    type:'GET',  
    url:'file.php',  
    data:'',
    success: function() {
        alert('RECORD SUCCESSFULLY INSERTED');
    }
});

On a similar note, it's better to use POST than GET when submitting forms.

Upvotes: 1

Related Questions