Breaking News

insert data in mysqli using html form explanation (lecture 5)

insert-data-in-mysqli-using-html-form-explanation
insert data in MySQL using HTML form explanation


How to fetch data from HTML form to store in the database?

For this two methods are used post and get we have to mention which one we want to use in the HTML and then use it in the PHP to fetch data and we set names to every field of the form to fetch using methods like get or post.

Example

html part   1:  <form method="method">  // which can be post or get.

                   2: <input type="text" id="lname" name="lastname" class="form-control" placeholder="Your                              lastname">


PHP part     $_POST[];   is used to fetch data form fields using name like $_POST['lastname'];

Difference between the post and get

1: the post is used to send data hidden to PHP                      1:  get is used to send data openly to PHP
2: post data is not shown in the URL                                  2:  get data is shown in the URL
3: It should be used as it is secured                                 3:  should not be used as not secured.

isset function 

isset() is a PHP function used widely in PHP. it is used to check if a certain thing is done of value is set so some task can be done.

Example

if(isset($_POST["submit"]))     //submit is the name of the button used to submit data.
{}

$_POST["submit"] is used in the isset function to check that if there is a value in the submit means this whole state is checking that if the user has submitted or not.

Fetching data

$firstname=$_POST['firstname'];    

data is fetched using post function and stored in the variable.

Query

$query="INSERT INTO `table`(`first_name`, `email`, `secound-name`, `phone`, `message) VALUES ('$firstname','$email','$lastname','$phone','$mess','1')";

this is the query to insert data in the database.

Want to learn about queries check out our database lectures

Run the query

$result=mysqli_query($connect,$query);

my sqli_result is a function in php used to run the query it has two parameters

  1. Connection (connection variable is passed in it)
  2. Query         (query variable is passed in it)

Check for errors

if(!$result)
{
die("Query failder" . mysqli_error($connect));
}


mysqli_error() is a function which identifies the error and helps us solve it.it needs only one parameter which is connect variable.

                                                                          Full Code

Previous Lecture










Post a Comment

1 Comments

  1. Thanks A Lord For Publish In Your Blog, This Is A Great Things To Learned Many Information. Keep Posting Many Blogs Like This.
    Web portal development company in chennai, Web portal development services in chennai

    ReplyDelete

Your Comment is Submitted