jeudi 2 mai 2019

How to send form data to MySQL database upon successful submission?

I have a form that I would like to have connected to MySQL database. I have my HTML, PHP to connect, and database all set up. I'm just not sure how to where to place my connect.php (within html? or how?) so that 'submit' will validate first, then insert data into database table, then have the data selected to display on the confirmation page.

Current Problem: Currently when I submit a valid form, the database does not receive any data because I have not successfully connected my form submit to the database.

My HTML form (shortened):

<form name="myForm" id="form" action="registration.php" method="POST">
/*form content*/
</form>

PHP - registration.php (contains validation.php) for form validation:

<?php
    include 'validation.php';
?>

<form name="myForm" id="form" action="/*php action*/" method="POST">
    /*form php info*/
</form>
<?php
    //var_dump($isValid);
    if ($isValid) {
    ?>
    <form id="hiddenForm" name="hiddenForm"
          method="POST" action="confirmation.php">
    /*other php code*/
?>
<script> document.createElement('form').submit.call(document.getElementById('hiddenForm'));
</script>

<?php
    }
    ?>

connect.php my simple php code to connect to database: (Not sure how to connect this to form)

<?php
$user = 'root';
$password = '';
$db = 'project';

$db = new mysqli('localhost', $user, $pass, $db) or die("Unable to connect");

?>




Aucun commentaire:

Enregistrer un commentaire