我試圖從列表下拉菜單中將值與幾個地方的名稱傳遞。這些名稱將通過AJAX傳遞給php,用作查詢xls中要導出的特定地點表的參數。但是php代碼沒有被執行。任何人都可以幫助我。感謝使用AJAX將值從html傳遞到php
下面是代碼:
的index.html
<li><a href="#">Reports by Barangay</a>
<ul>
<li><a href="" id="libertad">Libertad</a></li>
<li><a href="#" id="sanvicente">San Vicente</a></li>
<li><a href="#" id="ampayon">Ampayon</a></li>
<li><a href="#" id="mahogany">Mahogany</a></li>
</ul>
</li>
<script type="text/javascript">// <![CDATA[
$(document).ready(function(){
$("#libertad").click(function(){
var libertad=$("#libertad").val();
var postdata={
'libertad':libertad
};
$.ajax({
type: "POST",
url: "export.php",
data: postdata,
success: function(msg)
{
alert('success');
}
});
});
</script>
export.php
<?php
$value=$_POST['libertad'];
$DB_Server = "localhost";
$DB_Username = "root";
$DB_Password = "";
$DB_DBName = "places";
$DB_TBLName = $value;
$sql = "Select * from $DB_TBLName";
$Use_Title = 1;
$now_date = DATE('m-d-Y H:i');
$title = "RDI files on $now_date";
$Connect = @MYSQL_CONNECT($DB_Server, $DB_Username, $DB_Password)
or DIE("Couldn't connect to MySQL:<br>" . MYSQL_ERROR() . "<br>" . MYSQL_ERRNO());
//select database
$Db = @MYSQL_SELECT_DB($DB_DBName, $Connect)
or DIE("Couldn't select database:<br>" . MYSQL_ERROR(). "<br>" . MYSQL_ERRNO());
//execute query
$result = @MYSQL_QUERY($sql,$Connect)
or DIE("Couldn't execute query:<br>" . MYSQL_ERROR(). "<br>" . MYSQL_ERRNO());
什麼呢螢火蟲顯示器或任何其他CONSOL輸出? – 2013-02-13 15:11:04
您正在使用[an **過時的**數據庫API](http://stackoverflow.com/q/12859942/19068)並應使用[現代替換](http://php.net/manual/en/) mysqlinfo.api.choosing.php)。你也**易受[SQL注入攻擊](http://bobby-tables.com/)**,現代的API會使[防禦]更容易(http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php)自己從。 – Quentin 2013-02-13 15:11:51