using jquery in mysql php

Posted by JPro on Stack Overflow See other posts from Stack Overflow or by JPro
Published on 2010-03-19T19:28:05Z Indexed on 2010/03/19 19:31 UTC
Read the original article Hit count: 281

Filed under:
|
|

I am new to using Jquery using mysql and PHP I am using the following code to pull the data. But there is not data or error displayed.

JQUERY:

<html>
<head>
      <script>
    function doAjaxPost() {
     // get the form values
     var field_a = $("#field_a").val();

    $("#loadthisimage").show();
     $.ajax({

       type: "POST",
       url: "serverscript.php",
       data: "ID="+field_a,
       success: function(resp){
         $("#resposnse").html(resp);
    $("#loadthisimage").hide();
       },
       error: function(e){
         alert('Error: ' + e);
       }
     });
    }
    </script>
</head>
<body>
<select id="field_a">
 <option value="data_1">data_1</option>
 <option value="data_2">data_2</option>
</select>
<input type="button" value="Ajax Request" onClick="doAjaxPost()">
<a href="#" onClick="doAjaxPost()">Here</a>
</form>
<div id="resposnse">
<img src="ajax-loader.gif" style="display:none" id="loadthisimage">

</div>
</body>

and now serverscript.php

  <?php
    if(isset($_POST['ID'])) {
    $nm = $_POST['ID'];
    echo $nm;
    //insert your code here for the display.
    mysql_connect("localhost", "root", "pop") or die(mysql_error());
    mysql_select_db("JPro") or die(mysql_error());
    $result1 = mysql_query("select Name from results where ID = \"$nm\" ") or die(mysql_error());  

    // store the record of the "example" table into $row
    while($row1 = mysql_fetch_array( $result1 )) {
    $tc = $row1['Name'];

    echo $tc;
    }
    }
?>

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql