Skip to main content
1 of 7
user avatar
user avatar

HTML form not submitting data through php to my database

I need help getting my HTML form to submit data to my database (phpmyadmin). The database connects fine and everything but it can't seem to bridge the data into the database. I'm using Notepad++ as my text editor and tester. This is for a project ahead of time in class, I need to understand how to do this for it.

HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Record Form</title>
</head>
<body>
<form action="insert.php" method="post">
    <p>
        <label for="firstName">TechID:</label>
        <input type="text" name="techid" id="TechID">
    </p>
    <p>
        <label for="lastName">First Name:</label>
        <input type="text" name="firstname" id="FirstName">
    </p>
    <p>
        <label for="emailAddress">Last Name:</label>
        <input type="text" name="lastname" id="LastName">
    </p>
    <p>
        <label for="emailAddress">Phone:</label>
        <input type="text" name="phone" id="Phone">
    </p>
    <p>
        <label for="emailAddress">Email:</label>
        <input type="text" name="email" id="Email">
    </p>
    <p>
        <label for="emailAddress">State:</label>
        <input type="text" name="state" id="State">
    </p>
    <p>
        <label for="emailAddress">Address:</label>
        <input type="text" name="address" id="Address">
    </p>
    <p>
        <label for="emailAddress">Zipcode:</label>
        <input type="text" name="zipcode" id="Zipcode">
    </p>
    <p>
        <label for="emailAddress">Date:</label>
        <input type="text" name="date" id="Date" placeholder="EX: 2017-7-25">
    </p>
    <p>
        <label for="emailAddress">Course:</label>
        <input type="text" name="course" id="Course">
    </p>
    <p>
        <label for="emailAddress">Request:</label>
        <input type="text" name="request" id="Request">
    </p>
    <input class="submit" name="submit" type="submit" value="Insert">
</form>
</body>
</html>    

PHP

<?php
$link = mysqli_connect("localhost", "root", "", "student_request");

if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
 
if(isset($_POST['submit'])){ 
$techid = $_POST['techid'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$state = $_POST['state'];
$address = $_POST['address'];
$zipcode = $_POST['zipcode'];
$date = $_POST['date'];
$course = $_POST['course'];
$request = $_POST['request'];

$sql = "INSERT INTO student (TECH_ID, FIRST_NAME, LAST_NAME, PHONE_NUM, EMAIL, STATE, ADDRESS, ZIPCODE, DATE, COURSE, REQUEST_TYPE) VALUES ('$techid','$firstname','$lastname','$phone','$email','$state','$address','$zipcode','$date','$course','$request')";
if(mysqli_query($link, $sql)){
    echo "Records inserted successfully.";
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
}
mysqli_close($link);

?>
user6471649