2013-01-10 21 views
1

在我的網頁我有以下代碼阿賈克斯不能發送數據在其他文件夾中的文件

insert.php

<?php 
include ("../config/config.php"); 
$state = $_POST['state']; 
$squery = mysql_query("INSERT INTO ctm_state(state) VALUES('$state')"); 
if($squery){ 
echo "Data for $state inserted successfully!"; 
} 
else{ echo "An error occurred!"; } 
?> 

state.php

<script type="text/javascript"> 
$(document).ready(function(){ 
$("#insert").click(function(){ 
var state=$("#state").val(); 
$.post('ctmadmin/ajax_state.php', {state: state}, 
function(data){ 
$("#message").html(data); 
$("#message").hide(); 
$("#message").fadeIn(1500); //Fade in the data given by the insert.php file 
}); 
return false; 
}); 
}); 
</script> 

當使用上面的URL時,ajax可以正常工作並顯示插入數據的正確結果。但是,如果該URL被改變

.post的$( 'ctmadmin/phpqrcode/ajax_state.php',{狀態:狀態},

的ajax_state是叫phpqrcode其他文件夾,當我使用上面的網址它不插入DATAS到表不顯示在FrontPage東西。任何人都可以幫我解決這個問題

+0

'$ state' SQL注入警告。 – hsz

+0

檢查include(「config/config.php」)語句的相對路徑。我認爲它可能不會更新,當您將其移動到另一個文件夾 –

回答

1

如果移動insert.php成子目錄,其包括將失敗,因爲它有一個相對路徑,你可以前綴它與../

include ("../config/config.php"); 
+0

不工作我將包括替換爲包括(「../config/config.php」); – Rithu

+0

檢查你的錯誤日誌,並驗證'config.php'是否在'ctmadmin/config/config.php'中。 – MrCode

+0

是的。這個文件存在。但在上面的代碼中,我放錯了包含。 include(「../config/config.php」);是目前的網址ctmadmin/ajax_state.php',如果我更改我的網址爲ctmadmin/phpqrcode/ajax_state.php我必須放置inlcude – Rithu