简体   繁体   中英

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?

Realistically I would change the form to run the PHP on the same page. 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:

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:

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM