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 trialAbe Layee
8,378 PointsMYSQL Query
Good day, my query is not inserting the database and I can't seem to figure it out. What am I doing wrong here?
<?php
session_start();
if(!$_SESSION['email']){
header("Location:index.php");
exit();
}
$query = " INSERT INTO employees(first_name,last_name,middle_
name,gender,social_security,dob,
organization,department,iden,position,
pay_rate,health_plan,dental_plan,vision_plan,address_one,address_
two,apartment,city,_state,zipcode,primary_phone,email) VALUES
($first_name,$last_name,$middle_name,$gender,$social_security,
$dob,$orangization,$department,
$identification,$position,$payrate,
$healthcare,$dental,$vision,
$address_one,$address_two,$apartment,
$city,$state,$zipcode,$phone_number,$email)";
$insert_query = mysqli_query($connect,$query);
if($query) {
echo "Query Failed"."<br>".mysqli_error($connect);
exit();
} else { echo "Success";}
}
//output
Query Failed
You have an error in your SQL syntax;
check the manual that corresponds to your MariaDB server version for the right syntax to use near
'Stack Developer,50.00,MetroPlus,Cigna,Guardian,400 John blv,300 Dav Blvd,' at line 1
?>
1 Answer
Erasto Oraro
5,610 PointsConsider enclosing all your string variables in single quotes, something like:
...Values ('$first_name','$last_name', ...)" or ...VALUES ('".$first_name'.", ...