duanhoupeng6642 2014-01-15 07:17
浏览 44
已采纳

单击按钮时的TRUNCATE表

Somehow my query is not working when I click the button. What I'm trying to do is to TRUNCATE the table when the user click the button.

if(isset($_POST['extract'])){

@mysql_query("TRUNCATE TABLE temp");

}

I also tried this:

if(isset($_POST['extract'])){

$myquery = mysql_query("TRUNCATE TABLE temp");

}

Why is it not executing?

This is the html code:

<input type="submit" value="Extract CSV file" name="extract">
  • 写回答

2条回答 默认 最新

  • douqilai4263 2014-01-15 07:27
    关注

    So here is how would approach to debugging this problem:

    1) Check if the form is actually submitted. Put this on the top of your PHP file (note: for debugging only)

    echo "I have reached my destination";
    die();
    

    2) Check if you are submitting via POST or GET. Or easier, replace $_POST with $_REQUEST, which contains both $_POST and $_GET.

    if(isset($_REQUEST['extract'])){
    

    3) Ensure the connection to the database is opened.

    4) Provide your script the means to tell you if the query executed successfully

    $myquery = mysql_query("TRUNCATE TABLE temp") or die("Error: ".mysql_error());
    

    5) Ensure you are looking at the right place for the changes

    You would be surprised how easy it is to get confused with multiple databases opened.
    Double check the ip address of your DB server, your DB and table name and contents.
    

    One of the above 5 steps will tell you what went wrong.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?