PHP通过post在表单提交上动态生成页面

发布于 2024-10-23 19:15:49 字数 303 浏览 1 评论 0原文

我有一个关于 php 和 mysql 的一般问题。

因此,目前,我在 html 文件中有一个表单,该表单在 sumbit 上发布到 code.php,并在 code.php 中进行一些输入处理。

我将如何在使用 mysql 提交时生成不同的页面并向它们显示 code.php 的结果?

例如,我有我的域 example.com,在提交时,它将生成一个页面 example.com/1.php,之后,如果我刷新页面并再次点击提交,它将生成 example.com/ 2.php?

我知道我的问题非常笼统,只是在寻找教程或代码示例!

I have a general question about php and mysql.

So currently, I have a form in a html file that on sumbit gets posted to a code.php with some input processing in code.php.

How would I go about generating different pages on submit with mysql and showing them the result from code.php?

So for instance, I have my domain example.com and on submit, it would generate a page example.com/1.php, and after, if I were to refresh the page and hit submit again, it would generate example.com/2.php?

I know my question is very general, just looking for a tutorial, or example to code to follow!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

半夏半凉 2024-10-30 19:15:49

我实际上认为您要求的是逐步添加过程之类的东西?

那么我在第1页、第2页、第3页写的内容首先要添加到第4页吗?

如果是这种情况,您应该阅读 PHP 中的 serialize() 函数。

例如,在帖子中你可以这样做:
if( isset($_POST['step1']) )
{
$_SESSION['step1_ok'] = 1;
然后

使用会话来检查用户是否来自上一步。 :)

I actually think what you are asking for is something like a step-by-step add process?

So what I write in page 1, page 2 and page 3 firstly wants to be added on page 4?

If that is the case you should read about serialize()-function in PHP.

E.g. on post you could make this:
if( isset($_POST['step1']) )
{
$_SESSION['step1_ok'] = 1;
}

And then use the session for checking if the user comes from the last step. :)

絕版丫頭 2024-10-30 19:15:49

我不明白你的意思,但要创建一个文件,你可以使用 fopen。

I don't get your point, but to create a file you use fopen.

断肠人 2024-10-30 19:15:49

不确定这一点,您是否想要一个包含多个页面的表单?

您可以在 1 个 php 页面中执行此操作,例如:

<?php

  if(isset($_POST['step'])) {
    $step = $_POST['step']; 
  }
  else {
    $step = 1;
  }

  if($step == 3) {
    //show s3rd page
  }
  else if($step == 3) {
    //show 2nd page
  }
  else {
    //show 1st page
  }
?>

如果您想要 1.php、2.php、3.php,.....

那么您应该使用 mod_rewrite 执行某些操作,以将所有这些请求发送到“代码” .php',然后你会执行类似上面的操作来找出他们尝试访问哪些虚拟页面

生成 php 代码,然后将其保存为 php 文件,然后执行该文件会给你带来很多安全问题。

Not sure the point of this, are you trying to have a form that contains multiple pages?

You could just do that in 1 php page with something like:

<?php

  if(isset($_POST['step'])) {
    $step = $_POST['step']; 
  }
  else {
    $step = 1;
  }

  if($step == 3) {
    //show s3rd page
  }
  else if($step == 3) {
    //show 2nd page
  }
  else {
    //show 1st page
  }
?>

If you want the 1.php, 2.php, 3.php,.....

Then you should do something with mod_rewrite to make all those requests to to 'code.php' and then you would do something like above to figure out which of the virtual pages they tried accessing

Generating php code and then saving it as a php file which is then executed opens you up to a lot of security issues.

空城仅有旧梦在 2024-10-30 19:15:49

如果您的目标是出于美观原因创建您所描述的 URL,也许您应该研究 mod_rewrite 或类似的东西。

http://articles.sitepoint.com/article/guide-url-rewriting

If your goal is to create the URL as you described for cosmetic reasons, perhaps you should look into mod_rewrite, or something similar.

http://articles.sitepoint.com/article/guide-url-rewriting

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文