2016-03-01 18 views
-1

我正在盡我所能地製作一個表單,在網上商店名稱存在的情況下檢查我的數據庫,但是我現在正在將我的頭靠在牆上。所以用戶在表單中設置了一個名字。如果網店存在錯誤:「網店名稱不可用」,則表單下面的範圍內。JQuery沒有從表格中調用

這段代碼沒有任何工作,所以我當然犯了一些錯誤,但我應該從哪裏開始尋找?數據庫連接工作正常,我沒有在我的開發人員控制檯中發現任何錯誤。

問候

<form group="form-horizontal" id="webshopform" action="createWebshop.php" method="post" role="form"> 
    <div class="form-group has-feedback"> 
     <label for="Webshop-Succes">Webshop Name</label> 
     <input type="text" class="form-control" name="createWebshopInput"> 
     <span class="glyphicon glyphicon-ok form-control-feedback"></span> 
    </div> 
</form> 

JS:

$(document).ready(function() { 
    $('#webshopform').formValidation({ 
     framework: 'bootstrap', 
      fields: { 
       createWebshopInput: { 
        remote { 
         message: 'The Webshop name is not avaible', 
         url: 'webshopcheck.php', 
         data: "dbconfic.inc.php", 
         dataType: 'json' 
        } 

       } 
      } 
    }); 
}); 

webshopcheck.php:

<?php 
ini_set('display_errors', 1); 
ini_set('display_startup_errors', 1); 
error_reporting(E_ALL); 
include 'dbconfic.inc.php'; 

if(isset($_POST['createWebshopInput']) && $_POST['createWebshopInput'] != '') 
    { 
     $response = array(); 
     $shop = mysqli_real_escape_string($mysqli,$_POST['createWebshopInput']); 
     $sql = "SELECT name FROM webshops"; 
     $res = mysqli_query($mysqli, $sql); 
     $count = mysqli_num_rows($res); 
     if($count > 0) 
     { 
      $response['status'] = false; 
      $response['msg'] = 'Webshop Already Exist.'; 
     } 
     else 
     { 
      $response['status'] = true; 
      $response['msg'] = 'Webshop available.'; 
     } 
     echo json_encode($response); 
    }?> 
+1

@wahwahwah 「這個代碼工作,現在的無」 - >在代碼審查,這個問題是題外話。 – Pimgd

+0

你知道嗎,我的問題不是真的,因爲我說「這段代碼現在沒有任何工作」,所以我的問題是脫離php,qjuery和html的話題。 – Julie24

+0

我只是在編輯我的問題,所以人們可以看到我編輯了弗雷德。 – Julie24

回答

1

我不是很熟悉,你正在使用的jQuery插件,但敷衍的瀏覽文檔顯示,你錯過了配置中的關鍵/對象validators guration。

這裏是你的Javascript應該怎麼可能看的(未經測試)例如:

$(document).ready(function() { 
$('#webshopform').formValidation({ 
    framework: 'bootstrap', 
     fields: { 
      createWebshopInput: { 
       validators: { 
        remote: { 
         message: 'The Webshop name is not avaible', 
         url: 'webshopcheck.php', 
         data: "dbconfic.inc.php", 
         dataType: 'json' 
        } 
       } 
      } 
     } 
    }); 
}); 

,我的文檔注意到的另一件事是,你可能需要指定一個HTTP請求類型,如POSTGET

Here's the link to the pertinent part of the docs...

編輯:Here is documentation that is more pertinent, while the other one is more of an example.

+0

謝謝你的答案Tjons。很高興看到有人真的在這裏幫助,而不是寫我的問題不在話下。我現在將調查它 – Julie24

+0

這是真的我沒有看到。我將只修改我的代碼。 – Julie24

+0

它正在工作。非常感謝:-) – Julie24