Tags
Asked 3 years ago
9 Jun 2021
Views 286
debugger

debugger posted

HTML form submit to PHP script

HTML form submit to PHP script
david

david
answered Apr 25 '23 00:00

To pass form data to another page using PHP, you can use the HTTP POST method. Here is an example of how you can do this:

1.Create a form in the HTML code of your page. For example:


<form action="submit.php" method="POST">
  <label for="name">Name:</label>
  <input type="text" id="name" name="name">
  <label for="email">Email:</label>
  <input type="email" id="email" name="email">
  <input type="submit" value="Submit">
</form>

2.In the action attribute of the form, specify the URL of the PHP script that will receive the form data. In this example, the script is called submit.php.

3.In the PHP script that receives the form data (in this case, submit.php) , you can access the data using the $ _POST superglobal variable. For example:


<?php
  $name = $_POST['name'];
  $email = $_POST['email'];
  // do something with the form data, e.g. store it in a database
?>

Note that you should always validate and sanitize the form data before using it in your PHP code to prevent security vulnerabilities such as SQL injection attacks.
Post Answer