简体   繁体   English

我创建了一个html提交按钮,并与php代码连接,但是,选择之后,我该如何返回我的html页面?

[英]I have created one html submit button and connects with php code but, after selecting that how can i go back my html page?

 <?php
       if($run == TRUE)
        echo "Data Inserted Successfully <a href='index.html'>Click here to insert more</a>";
    else
        echo "Error !";enter code here
?>

I have created one html submit button and connects with php code but, after selecting that how can i go back my html page? 我创建了一个html提交按钮,并与php代码连接,但是,选择之后,我该如何返回我的html页面?

Realistically I would change the form to run the PHP on the same page. 实际上,我将更改表单以在同一页面上运行PHP。 So on the line where you create a form, instead of putting <form action='whatever.php'></form> I'd remove the action piece, then move the PHP script onto the same page (make sure it's .php instead of .html), and then wrap your whole script in something like this: 因此,在创建表单的那一行中,我将删除动作片段,然后将PHP脚本移至同一页面(确保它是.php),而不是放置<form action='whatever.php'></form>而不是.html),然后将整个脚本包装成如下形式:

if (isset($_GET['submit'])){ //or post depending on if you're using POST for your form, which is set by doing method=POST (suggested) or method=GET when creating the form's HTML
    //your regular php script would go here :)
}

But if you insist on having the PHP on another page and having it direct back you can do it like such: 但是,如果您坚持要在另一页上放置PHP并将其直接返回,则可以这样进行:

die(header('Location: index.html')); //change index.html to the directory of the page (or even a URL) that you want them directed to

Best of luck to you! 祝您好运!

Use $_SERVER['PHP_SELF'] as action in the form 使用$_SERVER['PHP_SELF']作为表单中的操作

I would prefer you write your html in php file and then use $_SERVER['PHP_SELF'] this willl submit the data on the same page and you can handle the data of the form being on the same page/php file 我希望您在php文件中编写html,然后使用$ _SERVER ['PHP_SELF']这将在同一页面上提交数据,并且您可以处理在同一页面/ php文件中的表单数据

<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过1个提交按钮将html / php代码定向到两个不同的页面? - How can I get my html/php code to direct to two different pages from 1 submit button? 我有一个用PHP代码创建的HTML问题 - I have an issue with HTML that created with php code 如何创建使用PHP连接到数据库的HTML登录名? - How can I create a HTML login that connects to a database with PHP? 如何使用 HTML 和 PHP 使用提交按钮将行 ID 发送到链接页面? - How can I send a row ID to a linked page using a submit button using HTML and PHP? 输入提交按钮后,如何更改从文本框中获取价值的HTML代码? - How can I change this html code that take value from text-box after enter submit button? 我没有 index.html,我有 index.php。 我的代码去哪里了? - I dont have index.html, I have index.php. Where does my code go? 如何将一个HTML表单提交到多个php文件? - How can I submit one HTML form to multiple php files? 当我提交 HTML 表单时,我的 PHP 代码如何运行 - How can my PHP code run when i submit a HTML form 我的HTML表单将其操作链接到php代码。 但是,当单击“提交”按钮时,表单将重定向到PHP文件。 我该如何预防? - My HTML form has its action linked to php code. When the submit button is clicked though, the form redirects to the PHP file. How can I prevent this? HTML | 我可以在一个按钮中分配 type=button 和 type=submit 吗? - HTML | Can I assign type=button and type=submit in one button?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM