2016-05-13 45 views
-1

我已經編寫了手機號碼驗證腳本,您可以在下面看到。問題它與URL1工作正常,但不是與URL2。我想知道爲什麼?手機號碼驗證如何隨着URL而變化?

URL1 - http://axbc.com/con/s2.php

URL2 - http://axbc.com/con/s2.php?key=d908e8401774411861043

這裏是我的代碼

if(isset($_POST['btn-signup'])) 
{ 

    $mobilenumber = $_POST['mobilenumber']; 
    if(!empty($dialogmobilenumber)) // phone number is not empty 
    { 
     if(preg_match('/^947\d{8}$/',$mobilenumber)) // phone number is valid 
     { 
      echo 'success'; 

     } 
     else // phone number is not valid 
     { 
      echo "<script>alert('Mobile Number is Not valid.. Format should be '); 

       </script>"; 

     } 
    } 
} 
+0

你發佈到URL2嗎? – sonique

+0

@sonique實際上它是使用GET – colombo

+0

得到的隨機數,因爲你使用$ _POST訪問變量,你永遠不會得到第2行。也許你應該在腳本結尾處移動else代碼,不確定這裏的邏輯是什麼。 – sonique

回答

1

你的代碼是在這兩個URL的工作對我罰款。 它在做什麼,它是什麼意思,它匹配從'947'+ 8號開始的所有11位數字。

因爲你沒有在這段代碼中的任何地方使用傳遞的變量,所以它永遠不會是你錯誤的原因。

有一件事,你正在接收移動號碼作爲POST在$mobilenumber變量。 那麼,爲什麼你使用$dialogmobilenumber來檢查它是否爲空? 您是否已經在程序中的任何位置定義了這一點。

if(!empty($dialogmobilenumber)) // phone number is not empty 
    { ... 

另一件事,您的表單也存在於s2.php? 如果不是,你的行爲包含(action="?")的表單是什麼?

注意:如果您可以粘貼完整代碼並輸出 URL2,那會很好。