I am trying to pass the value from a list dropdown menu with names of several places. These names will be passed to php using AJAX to be used as argument in querying a specific table of places to be exported in xls. But the php code was not being executed. Could anyone help me with this. Thanks
Here are the codes:
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());