0

我是 PHP 新手。

我的要求是一旦表单值保存到 mysql 数据库中,它需要将输入的值显示到弹出窗口中。

我做了这部分。问题总是打开新标签并显示细节。它没有打开弹出窗口。

    <?php

error_reporting(E_ALL);
ini_set('display_errors', 'On');
//echo '<pre>';
//echo print_r($_POST);
//echo '</pre>';

$message = "";
$firstname ="";
$lastname = "";
$email = "";
$mobile = "";
$nic = "";
$msg ="";
$genrateID = "";

if ( isset ( $_POST['Submit'] ) ){
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $email = $_POST['email'];
    $mobile = $_POST['mobile'];
    $nic = $_POST['nic'];

    if($firstname ==''){
        $message .= "Enter firstname";
    }else if($lastname ==''){
        $message .= "Enter lastname";
    }else if($email==''){
        $message = "Enter email address";
    }else if(!is_valid_email($email)){
        $message .= "Enter valid email address";
    }else if($mobile==''){
        $message = "Enter email address";
    }else if(!is_valid_phone($email)){
        $message .= "Enter valid email address";
    }else if($nic==''){
        $message = "Enter nic number";
    }else if(!is_valid_nic($nic)){
        $message .= "Enter valid nic address";

    }else{
        if(empty($message)){
             $con = mysql_connect("192.168.1.5","root","root");
             if (!$con){
                die('Could not connect: ' . mysql_error());
                exit;
             }
             mysql_select_db("customerinfo", $con);
             $genrateID =uniqid (rand(), true);
             // mysql_query("INSERT INTO customerinfo (firstname ,lastname,email,mobile,nic) VALUES ('$firstname', '$lastname','$email','$mobile','$nic')" ) or die(mysql_error());
             $status = mysql_query("INSERT INTO customer (firstname ,lastname,email,mobile,nic,customerID)
             VALUES ('$firstname', '$lastname','$email','$mobile','$nic','$genrateID')");
            if($status =='1'){
                $msg ="Data has been saved successfully";


 $link = "<script>window.open('http://localhost/UserCRM/result.php?firstname=$firstname&lastname=$lastname&mobile=$mobile&email=$email&id=$genrateID','menubar=no,width=430,height=360,toolbar=no')</script>";
                echo $link;
                $message = "";
                $firstname ="";
                $lastname = "";
                $email = "";
                $mobile = "";
                $nic = "";
                $genrateID ="";
               // $msg ="";

            }else{
                $msg = "Data has been saved unsuccessfully!!";
            }
            mysql_close($con);
        }

    }
}


?> 

我的表格是:

  <form id="form" method="post" action="index.php" style="width:700px;" >..... </form>

请指出我的代码有什么问题。

提前致谢。

4

1 回答 1

0

问题是 Firefox 默认在新选项卡而不是新窗口中打开 URL。有关更多信息,请参阅此问题。提供窗口名称对我有用(firefox 16.0.2 linux)。

window.open('http://stackoverflow.com', 'new window', 'menubar=no, width=430, height=360, toolbar=no');
于 2012-11-20T19:01:18.950 回答