Gotham Gotham - 7 months ago 11
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?

Answer

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

mysqli_connect('host','username','password','databasename');
$sql = sprintf("INSERT INTO table_name VALUES ('%s','%s',...)",$field1,$field2,...);

both %s and variables number and position match.

mysqli_query($sql);

That should do...