Gotham Gotham - 5 months ago 8x
PHP Question

How do I link a html form with a sql databse table?

I have XAMPP running. I have a HTML form page that takes input from users (this file is saved with .php extension in htdocs). Upon clicking submit I want all the data in the forms to be saved in a table I created in mySQL ( Iam using phpmyadmin).How can I go about doing this?


create a new page process.php make html form action attribute to process.php

<form action="process.php" method="post">

in process.php

$field1 = $_POST['field1'];
$field2 = $_POST['field2'];

Repeat this for all your form fields and then use sql to save data to table

$sql = sprintf("INSERT INTO table_name VALUES ('%s','%s',...)",$field1,$field2,...);

both %s and variables number and position match.


That should do...