user74091 user74091 - 4 months ago 7
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

mysqli_query
, 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.

<?php
include('db.php');


$event_name='';
$place='';
$time='';
$date='';
$description='';



$event_name=strip_tags($_POST['event_name']);
$place=strip_tags($_POST['place']);
$time=strip_tags($_POST['time']);
$date=strip_tags($_POST['date']);
$description=strip_tags($_POST['event_description']);


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 {
die('failure');
}
}


and the html form

<body>
<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>

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

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

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

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

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

</form>
</div>





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
<text-area>
?

Answer

try this

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

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