0

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());
Eli
  • 1,256
  • 4
  • 29
  • 59
  • what does firebug displays or any other consol output? – mamdouh alramadan Feb 13 '13 at 15:11
  • 2
    You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Feb 13 '13 at 15:11

2 Answers2

0

val() is used for form elements like input, select and textarea

If you want to get the text in your link, you can use text():

var libertad=$("#libertad").text();
jeroen
  • 91,079
  • 21
  • 114
  • 132
  • yeah, I was able to get the text of the link using the text() but still the php file is not executed. Is the ajax function correct? – Eli Feb 14 '13 at 08:15
  • @Avelino The ajax function looks correct **if** you are using / including jQuery. – jeroen Feb 14 '13 at 13:12
0

give ul id='abc' to .click function in js

Mike
  • 23,542
  • 14
  • 76
  • 87
Azam Alvi
  • 6,918
  • 8
  • 62
  • 89