smith John
smith John

Reputation: 13

Make Pop Up in the same page (php)

I am trying to do pop up message on the same page.

$db->UpdateAddress($_POST['Cnum'],$_POST['Address']);
     echo "Address changed sucssefully";

i try to use this to display the popup but,the pop up is in blank page.

  $db->UpdateEmail($_POST['Cnum'],$_POST['mail']);
     $message = "E-mail changed sucssefully";
echo "<script type='text/javascript'>alert('$message');</script>";

thanks

<?php 


   class customer
   {
            public $db;

      public function OpenDB() // פתיחת בסיס נתונים
    {
      $ind_connect=mysql_connect("localhost","root","");
      $ind_db=mysql_select_db("project",$ind_connect);
      return $ind_connect;
    } 

       public function AddCustomers($CNumber,$Fullname,$id,$phoneNumber,$Address,$Email) // הכנסת נתונים של בן-אדם לבסיס נתונים
{
    $ind_connect=$this->OpenDB();
    $res=mysql_query("INSERT INTO `customers`(`Customer Number`,`Full Name`,`Id`,`Phone`,`Address`,`E-mail`)VALUES('$CNumber','$Fullname','$id','$phoneNumber','$Address','$Email')",$ind_connect);
}


   public function DeleteCustomers($NewCustomer) //מחיקת נתונים של בן-אדם  מבסיס נתונים 
{
    $ind_connect=$this->OpenDB();
    $id=mysql_query("SELECT `Customer Number` FROM `customers`",$ind_connect);
    $num_rows=mysql_num_rows($id);
    if($num_rows>0)
    {
        for($i=0;$i<$num_rows;$i++)
        {
            while($row=mysql_fetch_assoc($id))

                if($row['Customer Number']==$NewCustomer)
             {

                    $res=mysql_query("DELETE FROM `customers` WHERE `Customer Number` = '$NewCustomer'");
                    echo "Customer Deleted Successfully";

             }
        }
    }
}


        public function UpdateFullName($Cnumber,$Fname)
        {
    $ind_connect=$this->OpenDB();
    $res=mysql_query("UPDATE `customers` SET `Full Name`='$Fname' WHERE `Customer Number`='$Cnumber'",$ind_connect);

        }  
    public function UpdateId($Cnumber,$Id)
        {
    $ind_connect=$this->OpenDB();
    $res=mysql_query("UPDATE `customers` SET `Id`='$Id' WHERE `Customer Number`='$Cnumber'",$ind_connect);

        }  
        public function UpdatePhone($Cnumber,$Phone)
        {
    $ind_connect=$this->OpenDB();
    $res=mysql_query("UPDATE `customers` SET `Phone`='$Phone' WHERE `Customer Number`='$Cnumber'",$ind_connect);

        }  

    public function UpdateAddress($Cnumber,$Address)
        {
    $ind_connect=$this->OpenDB();
    $res=mysql_query("UPDATE `customers` SET `Address`='$Address' WHERE `Customer Number`='$Cnumber'",$ind_connect);

        }  

        public function UpdateEmail($Cnumber,$mail)
        {
    $ind_connect=$this->OpenDB();
    $res=mysql_query("UPDATE `customers` SET `E-mail`='$mail' WHERE `Customer Number`='$Cnumber'",$ind_connect);

        }  




  }

   ?>



<?php 


require_once "customerClass.php";
$db=new customer;
require_once "AdminClass.php";
$db2=new Admin; 
require_once "orderClass.php";
$db3=new Order; 


if (!(empty($_POST['Cnum'])&&empty($_POST['Fname'])&& empty($_POST['id'])&& empty($_POST['Pnumber'])&& empty($_POST['Address'])&&empty($_POST['mail'])))
{

        $db->AddCustomers($_POST['Cnum'],$_POST['Fname'],$_POST['id'],$_POST['Pnumber'],$_POST['Address'],$_POST['mail']);
        echo "Customer Added";
}


if (!(empty($_POST['Username'])&&empty($_POST['pass'])))
{

        $db2->AddAdmin($_POST['Username'],$_POST['pass']);
        echo "Admin Added";
}

   if(isset($_POST['del_Customer'])) 
{
        $db->DeleteCustomers($_POST['customer_number']);


}
 if(isset($_POST['updateorder']))
 {
     $db3->UpdateCustomerName($_POST['Onumber'],$_POST['name']);
     echo "Customer name changed sucssefully";

      $db3->UpdateProductName($_POST['Onumber'],$_POST['product_name']);
     echo "Product name changed sucssefully";

     $db3->UpdateCustomerNumber($_POST['Onumber'],$_POST['Cnumber']);
     echo "Customer number changed sucssefully";

      $db3->UpdateEmail($_POST['Onumber'],$_POST['email']);
     echo "E-mail changed sucssefully";

      $db3->UpdatePhone($_POST['Onumber'],$_POST['phone']);
     echo "Phone changed sucssefully";

       $db3->UpdateQuantity($_POST['Onumber'],$_POST['quantity']);
     echo "Quantity changed sucssefully";


    }   
     if(isset($_POST['Ucustomer']))
     {
            $db->UpdateFullName($_POST['Cnum'],$_POST['Fname']);
     echo "Customer name changed sucssefully";

              $db->UpdateId($_POST['Cnum'],$_POST['id']);
     echo "Id changed sucssefully";

            $db->UpdatePhone($_POST['Cnum'],$_POST['Pnumber']);
     echo "Phone Number changed sucssefully";

     $db->UpdateAddress($_POST['Cnum'],$_POST['Address']);
     echo "Address changed sucssefully";

      $db->UpdateEmail($_POST['Cnum'],$_POST['mail']);
     $message = "E-mail changed sucssefully";
echo "<script>alert(".json_encode($message).");</script>";



     }

        if(isset($_POST['updateadmin']))
        {
            $db2->UpdatePassword($_POST['Username'],$_POST['pass']);
     echo "Password changed sucssefully";
        }




    if(isset($_POST['signin']))
    {
        $db2->checkAdmin($_POST['User_name'],$_POST['password']);

    }

?>

Upvotes: 1

Views: 103

Answers (2)

Alaa M. Tekleh
Alaa M. Tekleh

Reputation: 7916

I recommend you to request changing email script via ajax in your javascript code and making alert on success callback as following code using jQuery Ajax function

jQuery.ajax({
      url: 'update-email.php',
      type: 'GET',
      dataType: 'json',
      data: {param1: 'value1', param2: "value2"},
      complete: function(xhr, textStatus) {
         //called when complete
      },
      success: function(data, textStatus, xhr) {
        //called when successful
        if(data.message){
           alert(message);
        }
      },
      error: function(xhr, textStatus, errorThrown) {
        //called when there is an error
      }
});

and in php you can return json result to javascript function via

$array = array("message"=>"your email updated successfully");
echo json_encode($array);

I hope my answer would be useful

Upvotes: 1

Nick
Nick

Reputation: 16576

Instead of echoing within the php script that's processing your change, you can redirect to the previous page with a GET variable in the URL. Let's say your previous page was user.php, you could replace the echo statement with something like

header('Location: user.php?email_changed'); 

Then, in the user.php page, you can add some code saying

if(isset($_GET['email_changed']) echo "...";

Upvotes: 0

Related Questions