在尝试使用表单通过php文件将用户数据存储到数据库之前,我想调用一些php文件,但问题是表单不能在一个表单中调用两个操作。
我的提交应该是重定向我做存储数据库和显示这些内容与php文件?
有没有人知道我做错了什么或者做了什么替代任务?
发布于 2011-12-15 12:00:47
如果您真的想将form、database_actions和display的页面分开
在包含表单的php文件中:
<form action="database_actions.php"><!-- means form posts to action.php //-->在database_actions.php中:
# Place code to insert into database and make sure
# no echo or print_f/r commands are issued
# and no spaces or line breaks at the top before `<?php`
# Then place this at the end of
header("Location: http://host/display.php");在display.php中,您可以显示任何输出。如果您有要传递的值,则可以通过会话强制移动。
这种方法在过去可能很好,但现在有很多方法可以正确地执行您脑海中的操作。其中之一是模型-视图-控制器设计模式。
当然,您最好使用MVC设计模式。下面是一个示例链接:
http://www.tonymarston.net/php-mysql/model-view-controller.html
您也可以在google中执行搜索。当然,您会发现更多关于MVC模式的内容。
https://stackoverflow.com/questions/8514629
复制相似问题