Please I am a newbie to Jquery and javascript however I am trying to parse a table name from jquery to a php page which which will be used to truncate a table. Please below is what I have tried so far...
Jquery page
$(function() {
$.winFocus(function(event, isVisible) {
if(isVisible){
var tableName="table1";
$("#isVisible").val(tableName);
}
else {
var tableName = "table2";
$("#isVisible").val("tableName");
}
});
})
The PHP form
//table name value from jquery
$tableName ='<div id="tableName"></div>';
// mysql query that truncates the table
$query = "TRUNCATE TABLE $tableName";
This does not give any error,yet it doesnt truncate the table. Please what am I doing wrong? Thanks for helping.
try this code to delete data from your table
$(document).ready(function(){
$("$btnID").click(function(){
$.post("deletePageName.php",{"tableName":'myTable'},function(data){
alert(data);
})
});
});
on php Page
<?
$tableName=$_POST["tableName"];
mysql_query("delete from ".$tableName);
echo "data clear";
?>
thank you