There are two buttons on the form, a submit button and a clear button. If the user pushes the clear button, your code sh
Posted: Sun May 15, 2022 1:28 pm
There are two buttons on the form, a submit button and a clear button. If the user pushes the clear button, your code should clear out all the entries in the form. Submit button. Once the user pushes the submit button the data will be available to a php script. Use the $_POST to retrieve the data from the form. Your code will need to: 1. Connect to the database. 2. Check for a valid connection. 3. Create the php to insert the form data. Here is a sample set of code: <?php include_once 'db.php'; // in this example, this file does the connection to the database if (isset($_POST['submit'])) { $name = $_POST['name']; $email = $_POST['email']; $mobile = $_POST['mobile']; $sql = "INSERT INTO users (name, email, mobile) VALUES ('$name', '$email', 'mobile')"; if (mysqli_query($conn, $sql)) { echo "New record has been added successfully !"; } else { echo "Error: ". $sql . ":-". mysqli_error($conn); ] mysqli_close($conn); } ?> The db.php code is: <?php $servername='localhost'; $username='root'; $password=''; $dbname = "my_db"; $conn=mysqli_connect($servername, $username, $password, "$dbname"); if(!$conn) { die ('Could not Connect Mysql Server:' .mysql_error()); ?>