用户确认是否提交正确怎么实现?
用户上传的xls文件后,先读取其中的内容到数组中$aData;然后显示在页面中。
现在希望添加一个功能,就是两个按钮类似的东西:"确认" "放弃"
在读取文件前
mysql_query('BEGIN');
读取后录入数据库中;并将内容显示在页面上,
如果用户点击确定则执行
mysql_query('COMMIT');
如果点击放弃则
mysql_query('ROLLBACK');
就这个验证的功能,不知道怎么实现。用button的onclick吗?怎么获得返回值呢?或是有其它好的方法?
不希望跳转到下一个页面再读取一次文件,因为内容可能会很多很花时间哈!
------解决方案--------------------
- PHP code
<?php
//test.php
if(isset($_GET['commit'])){
$res1 = mysql_query('COMMIT');
}
if(isset($_GET['rollback'])){
$res2 = mysql_query('ROLLBACK');
}
?>
<?php if(!empty($res1)){ ?>
<table>COMMIT</table>
<?php } ?>
<?php if(!empty($res2)){ ?>
<table>ROLLBACK</table>
<?php } ?>
<form name="form" action="" method="post">
<input type="button" name="commit" value="确认" onclick="a()"/>
<input type="button" name="rollback" value="放弃" onclick="b()"/>
</form>
<script language="JavaScript" type="text/javascript">
function a(){
document.form.action="test.php?commit=ok";
document.form.submit();
}
function a(){
document.form.action="test.php?rollback=ok";
document.form.submit();
}
</script>
<br><font color="#e78608">------解决方案--------------------</font><br>
方法错了,你把mysql的事务分拆给了两次请求,肯定行不通的<br>你需要实现的效果是啥?
<br><font color="#e78608">------解决方案--------------------</font><br><form action='' onsubmit="subCheck()"><br>...<br><br>function subCheck(){<br>var nm = document.getElementById("nameTest");<br>if(nm.value!="")<br>return true;//返回true才提交<br>return false;<br>}<br><br>
<br><font color="#e78608">------解决方案--------------------</font><br>不需要跳转的话那就用ajax请求服务器吧。 <div class="clear">
</div>









