我已经创建了一个html提交按钮,并与php代码连接,但在选择后,我如何才能回到我的html页面?

vbopmzt1  于 2021-06-24  发布在  Mysql
关注(0)|答案(2)|浏览(273)
<?php
       if($run == TRUE)
        echo "Data Inserted Successfully <a href='index.html'>Click here to insert more</a>";
    else
        echo "Error !";enter code here
?>

我已经创建了一个html提交按钮,并与php代码连接,但在选择后,我如何才能回到我的html页面?

lmvvr0a8

lmvvr0a81#

实际上,我会改变表单,在同一个页面上运行php。所以在创建表单的那一行,而不是 <form action='whatever.php'></form> 我会删除动作片段,然后将php脚本移到同一个页面上(确保它是.php而不是.html),然后将整个脚本 Package 为如下内容:

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 :)
}

但是,如果您坚持将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

祝你好运!

xxe27gdn

xxe27gdn2#

使用 $_SERVER['PHP_SELF'] 作为形式上的行为
我希望你在php文件中编写html,然后使用$\u server['php\u self']这将提交同一页上的数据,并且你可以处理同一页/php文件中的表单数据

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

相关问题