2014-03-01 38 views
-1

嗨,我有一個新手問題 我想驗證我的位置代碼,當位置代碼全部準備就緒 php告訴我,位置代碼是存在的 如何用PHP提前做到這一點...如何驗證位置碼當位置全部設置完畢?

if(isset($_POST['addbtn'])){ 

    $lcode = $_POST['locationcode']; 
    $ladd = $_POST['locationadd']; 

    $stationadd = $mysqli->prepare("INSERT INTO table_station (locationcode,locationaddress) 
            VALUES (?,?)"); 

    $stationadd->bind_param('is',$lcode,$ladd); 
    $stationadd->execute(); 
    $stationadd->close(); 
    $mysqli->close(); 

} 

回答

2

你能做到在兩個方面:

1表單POST後: 你必須寫SELECT查詢語句從現有數據庫的詳細信息檢查「locationcode」,如果它與你的DB值相匹配那麼你不執行INSERT查詢直接重定向噸o您的以前的表單與錯誤味精一起。

2. AJAX: 它會幫助你檢測你插入「locationcode」出現在你的數據庫,並無須提交form..if它「locationcode」已經存在的數據庫,然後彈出警報味精返回false ..

教程: www.ajax-tutor.com/post-data-server.html

+0

喜先生@Ashish 謝謝.. 用ajax 抱歉,因爲我在網絡發展是新.. – user3367242

+0

如何驗證我已經搜索小號爲你實施教程,因爲你是新的,http://www.ajax-tutor.com/post-data-server.html – Ashish

+0

哇謝謝這個例子.. 非常感謝你 它確定複製這個例子嗎? – user3367242