提交表格不会停留在同一页面上

2022-01-14 00:00:00 xampp php mysql html submit

这是我的表格:

    <form action="#" method="post">
      <input type="text" size="25" name="firstname" placeholder="First Name" value="<?php echo $fn; ?>"/>
      <input type="text" size="25" name="lastname" placeholder="Last Name" value="<?php echo $ln; ?>"/>
      <input type="text" size="25" name="username" placeholder="Username" value="<?php echo $un; ?>"/>
      <input type="text" size="25" name="email" placeholder="Email" value="<?php echo $em; ?>">
      <input type="text" size="25" name="email2" placeholder="Repeat Email" value="<?php echo $em2; ?>"/>
      <input type="password" size="32" name="password" placeholder="Password"/>
      <input type="password" size="32" name="password2" placeholder="Repeat Password"/><br />
      <input type="submit" name="reg" value="Sign Up!"/>

      </form>

在我的网站上并按下提交(在 xampp 中)时,我收到一条错误提示

When on my site and pressing submit (in xampp) I get an error stating

找不到对象!

在此服务器上找不到请求的 URL.上的链接引用页面似乎是错误的或过时的.请告知作者关于错误的那个页面.

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

如果您认为这是服务器错误,请联系网站管理员.

If you think this is a server error, please contact the webmaster.

错误 404

localhost Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7

localhost Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7

我对使用 php、css 和 javascript 进行编码有点陌生,但我已经尝试了 2 天来寻找解决方案,但我一直没有想出任何办法.

I am somewhat new to coding with php, css, and javascript but I've been trying to find a solution to this for 2 days and I keep coming up with nothing.

我只是想让表单在提交或按下登录后保持在同一页面上!

I am just trying to get the form to stay on the same page after submitting or pressing sign in!

如果有人可以提供帮助,那就太好了!谢谢阅读.

If anyone could help, that would be great! Thanks for reading.

推荐答案

不指定动作会将表单提交到当前页面:

Specifying no action will submit the form to the current page:

<form action="" method="post">

或者使用 $_SERVER['PHP_SELF']:

<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">

相关文章