Local Bloggers

Hi In this blog i will provide educational help ,Jobs,Social Media Tricks and Tips.

Breaking

PropellerAds
Showing posts with label Web Development. Show all posts
Showing posts with label Web Development. Show all posts

Wednesday, 17 January 2018

January 17, 2018

How to insert data using php & MySql

How to insert data using php & MySql

Insert Value In Mysql using php form

Many ways to use Insert data using php in mysql database but today we discuss
Core Php method.It is a basic and easy way to learn php with mysql.
We just Create a HTML page and form.


Explanation 

  1. first we create a html page and save into htdocs as a index.php.
  2. Than create a connection with your database .
  3. Make two input field and one submit button.
  4. Write the accurate name of your inputs fields and PHP variables e.g $_POST['value1'].
  5. Than Run this code with connection .
  6. for connection check another article .



Html Form
<!DOCTYPE html>
<html>
<head>
   <title>Hello World</title>
        <style >
       
     </style>
</head>
<body>
<form method="post" action="index.php">
     <input type="text" name="value1">
     <input type="text" name="value2">
      <input type="submit" name="submit" Value="Ok!"> 

</form>
</body>

</html>





we get Post Values from (HTML FORM)

 if(isset ($_POST['submit'])){
  
  $a=$_POST['Value1'];
  $b=$_POST['Value2'];
  $q="INSERT INTO (TABLE NAME)  (col name1,col name2(in database)) VALUES('$a','$b')";
  $run=mysql_query($q);

}



col name: mean you should write name of your database column.
$a,$b,$q,$run: is variable its not necessary but its good habit to store every value in variable.


for any query about my post please comment here below.
Keep Visiting this blog for more helpful article.
Regards (haider ali uppal(software Engineer))