How to Process HTML Form Data Using PHP For Beginners

Post Reply
cache
Member
Reactions: 12
Posts: 22
Joined: 6 years ago

#1

  1. <?php
  2. //include database connection here
  3.  
  4. if (isset($_POST['saveData'])) {
  5. //get entered data from form field below
  6. //use field names to get data
  7.  
  8. //get username
  9. $name=$_POST['username'];
  10.  
  11. //get email
  12. $email=$_POST['userEmail'];
  13.  
  14. //get mobile number
  15. $number=$_POST['phoneNumber'];
  16.  
  17. //save data to the database col1,col2 and col3 are Database  columns, change accordingly to reflect your table columns
  18. $qry="INSERT INTO tableNmae('col1','col2','col3') VALUES('$name','$email','$number')";
  19.  
  20. //run query
  21. $run_qry=mysqli_query($connect_string,$qry);
  22.  
  23.   //check if successfully or not
  24. if ($run_qry) {
  25.     echo "Data saved";
  26. }else{
  27.     echo "Something went wrong";
  28. }
  29. //$connect_string is connection string that you declared when you were instantiating connection to database
  30. }
  31. ?>
  32. <!DOCTYPE html>
  33. <html>
  34. <head>
  35.     <title>process Data</title>
  36. </head>
  37. <body>
  38. <!--DATA FORM, Make sure you replace process.php with your own data processing PHP script-->
  39. <form action="process.php" method="post" name="myForm">
  40. <input type="text" name="username" placeholder="enter username">
  41. <input type="email" name="userEmail" placeholder="enter email">
  42. <input type="number" name="phoneNumber" placeholder="enter mobile number"> 
  43.  
  44. <!--Submit Button to be triggered-->
  45. <input type="submit" name="saveData" value="Save Data">
  46. </form>
  47. </body>
  48. </html>

1
1 Image
Last edited by cache on Thu Mar 29, 2018 11:12 pm, edited 7 times in total.
cache
Member
Reactions: 12
Posts: 22
Joined: 6 years ago

#2

Make sure you replace process.php with your own data processing PHP script
0
Post Reply

Return to “LAMP (Linux, Apache, MySQL, PHP)”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests