2012-11-08 86 views
0

我是PHP新手。PHP一次表單保存顯示popupwindow

我的要求是將表單值保存到mysql數據庫中,它需要在彈出窗口中顯示輸入值。

我做了這部分。問題總是打開新標籤&顯示詳細信息。它沒有打開opoup窗口。

<?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> 

請指出我什麼是錯在我的代碼。

在此先感謝。

+0

不要使用'mysql_ *'函數。他們已棄用! –

+0

這條線突出了:'$ link =「「;' – irrelephant

+0

'VALUES('$ firstname','$ lastname','$ email','$ mobile','$ nic','$ ''''你插入字符串而不是變量值,丟失單引號 – iMoses

回答

0

問題是Firefox默認情況下在新標籤中打開了一個URL,而不是一個新窗口。有關更多信息,請參閱this question。提供一個窗口名稱對我來說是個竅門(firefox 16.0.2 linux)。

window.open('http://stackoverflow.com', 'new window', 'menubar=no, width=430, height=360, toolbar=no');