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条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测