user74091 user74091 - 1 year ago 41
MySQL Question

what is failing in my insert query?

I have a form to submit with post, to my table in my database. However whenever I hit submit is says failure. I had several validation scripts that I removed to try and figure out why the form was not submitting.

I checked many of the answered questions regarding INSERT using

, but none seemed to answer my question. I am aware the HTML structure is probably poor, this is just to get the script working correctly first. its really not complicated, I don't understand whats wrong here.

I have a registration form, and my other forms on the site I'm working on all work fine, update date their tables correctly. Don't know what I'm missing here.




if(isset($_POST['submit'])) {

$query = "INSERT INTO user_posts (title, location, time, date, description)";

$query .= "VALUES ($event_name','$place','$time','$date','$description')";

if (mysqli_query($connection, $query)) {

echo "<h2> your post has been submitted </h2>";
else {

and the html form

<div class="box-1">
<form action="create_post_script.php" method="post" id="event_form">

<div class="box-2">
<input type="text" name="event_name" placeholder="event title" />

<div class="box-3">
<input type="text" name="place" placeholder="location" id="box-3" />

<div class="box-4">
<input type="time" name="time" id="box-4" />

<div class="box-4">
<input type="date" name="date" id="box-4" />

<div class="box-5">
<h4> <center> ... </center> </h4>
<textarea class="text-area" name="event_description" id="event_form" >
<input type="submit" value="submit" name="submit" placeholder="submit"/>

<div class="box-6">
<div class="box-7">
<h4> </h4>


When I hit submit, the resulting page confirms my connection and says 'failure', is this because of the way that I have the submit input field for the

Answer Source

try this

$query = "INSERT INTO user_posts (title, location, time, date, description) "; 

$query .= "VALUES ('$event_name','$place','$time','$date','$description')";