To store data from html form to database table, First create the HTML form with input variable. Give unique name for input type boxes.
How to Store Form Data in Database using PHP
1 2 3 4 5 6 7 8 9 |
<form name="inpurform" action="" method="POST"> <input type="text" name="postinput1" value=""/> <input type="text" name="postinput2" value=""/> <input type="submit" name="Submit" value="Submit"/> </form> |
After submit this form, you can get input box value using GET or POST method.
After that use INSERT mysql query to insert the particular data in Database Table. Use below code for that.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<?php $value1 = $_POST['postinput1']; $value2 = $_POST['postinput2']; $dbhost = 'localhost:3036'; $dbuser = '********'; $dbpass = '********'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } $sql = "INSERT INTO document_data (column1, column2) VALUES ( '$value1', '$value2')"; mysql_select_db('****Database Name***'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not enter data: ' . mysql_error()); } echo "New Document data in database successfully\n"; echo "<br>"; mysql_close($conn); ?> |
As above code mentioned first receive the form post variable and than create a mysql connection with your database.
Use your database access in code. After doing this you can easily insert data in phpmyadmin using php.