这是我尝试清空表的代码,而且每次我使用名为delete的按钮时,它都不能正常工作。有人知道什么是这个查询的正确方法吗?请帮忙,谢谢。
if (isset($_POST['delete'])) {
$EmptyQuery = mysql_query("TRUNCATE TABLE `tblresult`", $connect);
};
<form id="NewEvaluation" method=post action=setnewevaluation.php onsubmit="return confirm('Are you sure you want to set a new evaluation? this will empty all the table for results,evaluate,answers and finalresults.');">
<input type="image" name='delete' id=confirm src="Confirmdean.jpg"/>
</form>发布于 2016-02-27 03:44:55
事情是这样的:
<input type="image" name='delete' id=confirm src="Confirmdean.jpg"/>作为提交的图像类型不会处理POST指令。
您需要使用实际的提交类型输入。
<input type='submit' name='delete' value='DELETE'>或者使用提交类型作为按钮:
<button type='submit' name='delete'>DELETE</button>这就是为什么您的代码没有在该条件语句中“触发”任何内容,也没有针对您的查询检查错误,这是我在评论中已经说过的两次。
$EmptyQuery = mysql_query("TRUNCATE TABLE `tblresult`", $connect) or die(mysql_error());发布于 2016-02-27 03:47:25
谢谢大家,现在一切都很好。问题是,我使用的是图像输入,而不是常规输入类型提交按钮。谢谢。
if (isset($_POST['delete'])) {
$EmptyQuery = mysql_query("TRUNCATE TABLE `tblresult`", $connect) or die(mysql_error());
$EmptyQuery1 = mysql_query("TRUNCATE TABLE `tblfinalresult`", $connect) or die(mysql_error());
$EmptyQuery2 = mysql_query("TRUNCATE TABLE `tblevaluate`", $connect) or die(mysql_error());
$EmptyQuery3 = mysql_query("TRUNCATE TABLE `tblanswer`", $connect) or die(mysql_error());
};
<form id="NewEvaluation" method=post action="" onsubmit="return confirm('Are you sure you want to set a new evaluation? this will empty all the table for results,evaluate,answers and finalresults.');">
<input type='submit' name='delete' value='DELETE'>
</form>发布于 2016-02-27 03:28:08
当错误信息不起作用时,是否收到任何错误消息?命令不起作用的频率是多少?在没有看到其他组件的情况下代码看起来是正确的。也许您可以尝试编写一些不同的代码,看看它是否有区别。
if (isset($_POST['delete'])) {
$query = "TRUNCATE TABLE table_name";
$EmptyQuery = mysql_query($query,$connect);
};我同意大角,截断是清空桌子的正确方法。
https://stackoverflow.com/questions/35665108
复制相似问题