在同一页面中弹出窗口(php)

时间:2016-07-04 18:30:31

标签: php

我正在尝试在同一页面上弹出消息。

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

我尝试使用它来显示弹出窗口,但弹出窗口是空白页。

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

感谢

<?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']);

    }

?>

2 个答案:

答案 0 :(得分:1)

我建议您通过javascript代码中的ajax请求更改电子邮件脚本,并使用jQuery Ajax函数在成功回调时发出警告,如下面的代码

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
      }
});

在php中你可以通过

将json结果返回给javascript函数
$array = array("message"=>"your email updated successfully");
echo json_encode($array);

我希望我的回答很有用

答案 1 :(得分:0)

您可以使用URL中的GET变量重定向到上一页,而不是在处理更改的php脚本中回显。假设你的上一页是user.php,你可以用

之类的东西替换echo语句
header('Location: user.php?email_changed'); 

然后,在user.php页面中,您可以添加一些代码

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