Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialtc11
19,518 PointsPHP script is not inserting into the database.
This script I made is not inserting into the database.
<?php
include 'mod2_config.php';
include 'mod2_opendb.php';
$employeeid= (isset($_POST['employeeid']) ? $_POST['employeeid'] : '');
$managementid= (isset($_POST['managementid']) ? $_POST['managementid'] : '');
$fname= (isset($_POST['first_name']) ? $_POST['first_name'] : '');
$lname= (isset($_POST['last_name']) ? $_POST['last_name'] : '');
$age= (isset($_POST['age']) ? $_POST['age'] : '');
$employment_period= (isset($_POST['employment_period']) ? $_POST['employment_period'] : '');
$sql= " INSERT INTO employees (employeeid, managementid, first_name, last_name, age, employement_period)
VALUES ('$employeeid ','$managementid', $fname','$lname','$age', '$employment_period')";
$result = mysqli_query($con, $sql);
$sql= " SELECT employeeid, managementid, first_name, last_name, age, employment_period from employees WHERE employeeid = $employeeid LIMIT 1";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "<b>Record successfully inserted:</b><br>";
echo "<b>EmployeeID: " . $row["employeeid"]. "</b><br>";
echo "<b>ManagementID: " . $row["managementid"]. "</b><br>";
echo "<b>Name: " . $row["first_name"]. " " . $row["last_name"]. "</b><br>";
echo "<b>Age: " . $row["age"]. "</b><br>";
echo "<b>Employment Period In Months: " . $row["employment_period"]. "</b><br>";
}
} else {
echo "Sorry there are no matches! Please check your entry and try again.";
}
mysqli_close($con);
?>
employeeid is AUTO INCREMENT Primary Key.