0

I am new to PHP.

My requirement is once the form value save into mysql database, it need to show the entered value into popup window.

I did this part .Problem is always open new tab & show detail. It didn't open opoup window.

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

    }
}


?> 

My form is :

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

Please indicate me what is wrong in my code.

Thanks in advance.

Piraba
  • 6,974
  • 17
  • 85
  • 135

1 Answers1

0

The problem is that Firefox opens a URL in a new tab by default rather than a new window. See this question for more info. Providing a window name does the trick for me (firefox 16.0.2 linux).

window.open('http://stackoverflow.com', 'new window', 'menubar=no, width=430, height=360, toolbar=no');
Community
  • 1
  • 1
Jonathan Dixon
  • 2,316
  • 23
  • 29