I need to pass some value to a PHP file and from this return some values to the original script. I wrote this code.
$(document).ready(function() {
var value = $('#myId').val();
$('.myClass').click(function() {
var request = $.ajax({
type: 'POST',
url: 'getinfo.php',
data: {fileIs: value},
success: function(data) {
alert(data);
},
error: function() {
alert("Error");
}
});
});
});
getinfo.php is like:
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("my_db") or die(mysql_error());
if(isset($_REQUEST['fileIs'])) {
$file = mysql_real_escape_string(htmlentities($_POST['fileIs']));
$value = mysql_query("SELECT * FROM files WHERE filename = '".$file."' ");
while($row = mysql_fetch_array($value)) {
echo $row['fileTitle'];
}
}
When i execute the script php AJAX function always return the alert with wrote "Error" that disappear automatically. How can i fix this problem? My goal is to send "value" variable content to the PHP file and get response from it to have the content in database corresponding to "value" content.