Not inserting into database. PHP and mysql - php

I have to create a form where answers get sent to the database but when I fill in the form the database is not updating and I have getting the self made error :"something went wrong". Can anyone see anything wrong? Thanks.
Form:
<form id="contact-form" method="post" action="sentEnquiries.php" name="enquiries">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="name">
Name</label>
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span>
</span>
<input type="text" class="form-control" id="name" name="name" placeholder="Enter name" required="required" /></div>
</div>
<div class="form-group">
<label for="email">
Email Address</label>
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span>
</span>
<input type="email" class="form-control" id="email" name="email" placeholder="Enter email" required="required" /></div>
</div>
<div class="form-group">
<label for="phoneNumber">
Phone Number</label>
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-earphone"></span>
</span>
<input type="tel" class="form-control" id="phoneNumber" name="phone" placeholder="Enter phone number" required="required" /></div>
</div>
<div class="form-group">
<label for="partySize">
Party Size</label>
<input type="number" min="1" max="6" class="form-control" id="partySize" name="partySize" required="required" />
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="arrivalDate">
Arrival Date</label>
<input type="date" class="form-control" id="arrivalDate" name="arrivalDate" />
</div>
<div class="form-group">
<label for="departureDate">
Departure Date</label>
<input type="date" class="form-control" id="departureDate" name="departureDate"/>
</div>
<div class="form-group">
<label for="name">
Message</label>
<textarea name="message" id="message" class="form-control" rows="9" cols="25" required="required"
placeholder="Message"></textarea>
</div>
</div>
<div class="col-md-12">
<button type="submit" class="btn btn-skin pull-right" id="btnContactUs">
Send enquiry</button>
</div>
</div>
</form>
Answers:
<?php
include("conn.php");
$sentName = $_POST['name'];
$sentEmail = $_POST['email'];
$sentPhone = $_POST['phone'];
$sentPartySize = $_POST['partySize'];
$sentArrivalDate = $_POST['arrivalDate'];
$sentDepartureDate = $_POST['departureDate'];
$sentMessage = $_POST['message'];
$insertQuery = "INSERT INTO Enquiries(enquiryID, name, email, phone, partySize, arrivalDate, departureDate, message) VALUES(NULL, '$sentName', '$sentEmail', '$sentPhone, '$sentPartySize', $sentArrivalDate, '$sentDepartureDate', '$sentMessage')";
?>
Further down answers doc:
<div class="descriptions">
<?php
if(mysqli_query($conn, $insertQuery)) {
echo "<p>Thank you for your enquiry.</p>";
mysqli_close($conn);
} else {
echo "<p>Something went wrong.</p>";
mysqli_close($conn);
}
?>
</div>

could you make sure as below :
enquiryID column, is this column is auto increment if not better you set the id become auto increment primary key
For debug purposes, can you echo first in $_POST['name'] then exit; to make sure that the post data from your html is work correctly.
if that not work, you should try to select first from database with simple query, so you will know the connection to database table is work correctly

Here is how i'd do it.
Change yours as required but here's my example:
PDO class:
class form
{
public function sendForm($name, $email, $phone, $party, $date, $depart, $message)
{
$stmt = $this->conn->prepare("INSERT INTO `enquiries` (`name`,`email`,`phone`,`partySize`,`arrivalDate`,`departureDate`,`message`) VALUES (:fname, :email, :phone, :party, :arrive, :depart, :msg)");
$stmt->bindParam(array(':fname' => $name, ':email' => $email, ':phone' => $phone, ':party' => $party, ':arrive' => $date, ':depart' => $depart, ':msg' => $message));
$stmt->execute();
}
}
Then within your form page:
$form = new form();
if (isset($_POST['sendIt']))
{
$form->sendForm($_POST['Fname'],$_POST['email'],$_POST['phone'],$_POST['size'],$_POST['date'],$_POST['depart'],$_POST['message']);
}
Then my basic form without the div tagging so you'll need to tweak slightly:
<form action="" method="post">
<input type="text" name="Fname">
<input type="email" name="email">
<input type="text" name="phone">
<input type="text" name="size">
<input type="text" name="date">
<input type="text" name="depart">
<textarea name="message" id="" cols="30" rows="10"></textarea>
<input type="submit" name="sendIt">
</form>
This is a very basic one with no thank you message or conditions but you can easily add conditions before running the query by doing
if (!empty($var)
{
// do something
} else {
echo "you didnt fill this in...";

Related

Submit button in a form not sending data?

I want to send my html form data to my database which I have created using XAMPP. But, for some reason, the submit button is not working.
This is my html code:-
<form id="contact" action="contact.php" method="post" class="php-email-form">
<div class="row">
<fieldset class="col-md-6 form-group">
<input type="text" name="name2" class="form-control" id="name" placeholder="Your Name" required>
</fieldset>
<fieldset class="col-md-6 form-group mt-3 mt-md-0">
<input type="email" class="form-control" name="email2" id="email" placeholder="Your Email" required>
</fieldset>
</div>
<fieldset class="form-group mt-3">
<input type="text" class="form-control" name="phone2" id="phone" placeholder="Your Phone Number" required>
</fieldset>
<fieldset class="form-group mt-3">
<input type="text" class="form-control" name="subject2" id="subject" placeholder="Subject" required>
</fieldset>
<fieldset class="form-group mt-3">
<textarea class="form-control" name="message2" rows="5" placeholder="Message" required></textarea>
</fieldset>
<fieldset class="text-center">
<button type="submit" name="submit" id="contact-submit">Send Message</button>
</fieldset>
</form>
This is my contact.php code:-
<?php
$name = $_POST['name2'];
$fromEmail = $_POST['email2'];
$phone = $_POST['phone2'];
$subject = $_POST['subject2'];
$message = $_POST['message2'];
//Database Connection
$conn = new mysqli('localhost','root','','contactus');
if ($conn->connect_error) {
die('Connection Failed : '.$conn->connect_error);
} else {
$stmt = $conn->prepare("insert into contact(Name, Email, Phone No., Subject, Message)
values(?,?,?,?,?)");
$stmt->bind_param("ssiss",$name,$fromEmail,$phone,$subject,$message);
$execval = $stmt->execute();
echo $execval;
echo "Sent Successfully";
$stmt->close();
$conn->close();
}
?>
In order for the system to properly process the data field Phone No. (which contains a space character) in db operation, Please enclose it by backticks in your insert query prepared statement
Change
$stmt = $conn->prepare("insert into contact(Name, Email, Phone No., Subject, Message) .....
to
$stmt = $conn->prepare("insert into contact(Name, Email, `Phone No.`, Subject, Message) .....
Your submit button ID is different than what is identified in the form.
<form id="contact" action="contact.php" method="post" class="php-email-form">
<button type="submit" name="submit" id="contact">Send Message</button>

How to make my update query work using my code below

I am setting up an update profile page using php and a bit of laravel. I have an if check that checks if the form is submitted and I have an update query.
The update query only works outside of the if statement and I have no idea why. If I put in inside of the if statement it doesnt do anything. I have checked if all the names are the same as in my sql database and they are all correct.
<form class="form" id="registrationForm">
<div class="form-group">
<div class="col-xs-6">
<label for="first_name">
<h4>Voornaam</h4></label>
<input type="text" class="form-control" name="voornaam" id="first_name" placeholder="<?= $user->voornaam; ?>" title="enter your first name if any.">
</div>
</div>
<div class="form-group">
<div class="col-xs-6">
<label for="last_name">
<h4>Achternaam</h4></label>
<input type="text" class="form-control" name="achternaam" id="last_name" placeholder="<?= $user->achternaam; ?>" title="enter your last name if any.">
</div>
</div>
<div class="form-group">
<div class="col-xs-6">
<label for="phone">
<h4>Gebruikersnaam</h4></label>
<input type="text" class="form-control" name="gebruikersnaam" id="username" placeholder="<?= $user->gebruikersnaam; ?>" title="enter your phone number if any.">
</div>
</div>
<div class="form-group">
<div class="col-xs-6">
<label for="mobile">
<h4>Telefoon nummer</h4></label>
<input type="text" class="form-control" name="telefoonnummer" id="mobile" placeholder="<?= $user->telefoonnummer; ?>" title="enter your mobile number if any.">
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
<label for="email">
<h4>Email</h4></label>
<input type="email" class="form-control" name="email" id="email" placeholder="<?= $user->email; ?>" title="enter your email.">
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
<br>
<button class="btn btn-lg btn-success" type="submit" name="submit"><i class="glyphicon glyphicon-ok-sign"></i> Sla op</button>
<button class="btn btn-lg" type="reset" name="resetww"><i class="glyphicon glyphicon-repeat"></i> Verander wachtwoord</button>
</div>
</div>
</form>
<?php
if (isset($_POST['submit'])) {
$voornaam = $_POST['voornaam'];
$achternaam = $_POST['achternaam'];
$gebruikersnaam = $_POST['gebruikersnaam'];
$telefoonnummer = $_POST['telefoonnummer'];
$email = $_POST['email'];
App\User::where('klant_id', 1)->update(['gebruikersnaam' => $gebruikersnaam, 'voornaam' => $voornaam, 'achternaam' => $achternaam, 'email' => $email ,'telefoonnummer' => $telefoonnummer]);
}
?>
I want my database to be updated
Put the tag in your form, the PHP is trying to find de POST but you are not sending it.
method="POST"
First of all mention form method as below and use csrf token
#csrf
Why u can't use controller to complete this work
First of all use controller, Then make a method to update information
public function update_user(Request $request){
if ($request->isMethod('post')) {
$data = $request->all();
User = new User();
$voornaam = $_POST['voornaam'];
$achternaam = $data['achternaam'];
$gebruikersnaam = $data['gebruikersnaam'];
$telefoonnummer = $data['telefoonnummer'];
$email = $data['email'];enter code here
}
}

My HTML form only returns 1 value into the PHP mail

The email I receive only shows the message, not the email address or phone number or even the name.
It also doesn't show from which email it has been sent.
I should receive whole information from the form, otherwise it wouldn't show me the message, I guess.
Maybe someone has more simple code than this one?
I tried but I'm stuck.
Can someone help me out?
Below is the HTML and PHP code
HTML Code:
<form name="mail" action="mail.php" method="post" >
<div class="form-group ">
<input id="name" class="form-control" placeholder="Name" type="text" required>
<label for="name" class="sr-only">Name</label>
</div>
<div class="form-group ">
<label for="email" class="sr-only">Email</label>
<input id="email" class="form-control" placeholder="Email" type="email" required>
</div>
<div class="form-group ">
<label for="phone" class="sr-only">Phone</label>
<input id="phone" class="form-control" placeholder="Phone" type="text" required>
</div>
<div class="form-group ">
<label for="message" class="sr-only">Message</label>
<textarea name="message" id="message" cols="30" rows="5" class="form-control" placeholder="Message" required></textarea>
</div>
<div class="form-group ">
<input class="btn btn-primary btn-lg" value="Send Message" name="submit" type="submit">
</div>
</div>
</form>
PHP code:
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];
$email_from = "$email";//<== update the email address
$email_subject = "New Form submission";
$email_phone = $phone;
$email_body = "You have received a new message from the user ".$name.
"\nHere is the message:\n ".$message.
"\nThe phone number:\n ".$phone.
"The email:\n ".$email.
$to = "info#czwebdesign.be";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: index.html');
?>
You also need to use name attribute for other fields as well same like message field, something like:
<input name="email" class="form-control" placeholder="Email" required>
<input name="name" class="form-control" placeholder="NAme" required>
<input name="phone" class="form-control" placeholder="Phone" required>
Otherwise you will get the Undefined Index warning in your script.
It's better to use php error_reporting() in your development mode, this will help to find out all errors and warnings in your code.
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
Try this
<form name="mail" action="mail.php" method="post" >
<div class="form-group ">
<input id="name" class="form-control" placeholder="Name" type="text" name="name" required>
<label for="name" class="sr-only">Name</label>
</div>
<div class="form-group ">
<label for="email" class="sr-only">Email</label>
<input id="email" name="email" class="form-control" placeholder="Email" type="email" required>
</div>
<div class="form-group ">
<label for="phone" class="sr-only">Phone</label>
<input id="phone" name="phone" class="form-control" placeholder="Phone" type="text" required>
</div>
<div class="form-group ">
<label for="message" class="sr-only">Message</label>
<textarea name="message" id="message" cols="30" rows="5" class="form-control" placeholder="Message" required></textarea>
</div>
<div class="form-group ">
<input class="btn btn-primary btn-lg" value="Send Message" name="submit" type="submit">
</div>
</div>
</form>
Look here at the missing name="" attribute in your <input>
Use this code instead:
<form name="mail" action="mail.php" method="post" >
<div class="form-group ">
<input name="name" id="name" class="form-control" placeholder="Name" type="text" required>
<label for="name" class="sr-only">Name</label>
</div>
<div class="form-group ">
<label for="email" class="sr-only">Email</label>
<input name="email" id="email" class="form-control" placeholder="Email" type="email" required>
</div>
<div class="form-group ">
<label for="phone" class="sr-only">Phone</label>
<input name="phone" id="phone" class="form-control" placeholder="Phone" type="text" required>
</div>
<div class="form-group ">
<label for="message" class="sr-only">Message</label>
<textarea name="message" id="message" cols="30" rows="5" class="form-control" placeholder="Message" required></textarea>
</div>
<div class="form-group ">
<input class="btn btn-primary btn-lg" value="Send Message" name="submit" type="submit">
</div>
</div>
</form>

Submit button will not send form data to MySQL database [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a problem that might be a syntax problem but I can't seem to figure out what I am doing wrong.
I have created a form and when I click on submit, the data in the form is not sent to my mysql database.
Here is my html code
<div class="content-wrapper">
<div class="container">
<div class="row">
<div class="col-md-10">
<h1 class="page-head-line">Forms </h1>
</div>
</div>
<div class="row">
<div class="col-md-10">
<div class="panel panel-default">
<div class="panel-heading">
BASIC FORM ELEMENTS
</div>
<div class="panel-body">
<form method="post" action="insert.php" >
<div class="form-group">
<label for="name">Name</label>
<input name="name' type="text" class="form-control" id="name" placeholder="Enter your name" required/>
</div>
<div class="form-group">
<label for="project_num">OIT-GIS Project Number</label>
<input name="project_num' type="text" class="form-control" id="project_num" placeholder="OIT-GIS Project Number" />
</div>
<div class="form-group">
<label for="project_name">Project Name</label>
<input name="name' type="text" class="form-control" id="project_name" placeholder="Project Name" required/>
</div>
<div class="form-group">
<label for="easyvista">EasyVista Ticket Number</label>
<input name="easyvista' type="text" class="form-control" id="easyvista" placeholder="EasyVista Ticket Number" />
</div>
<div class="form-group">
<label for="agency">Requestor/Agency</label>
<input name="agency' type="text" class="form-control" id="agency" placeholder="Requestor or Agency" />
</div>
<div class="form-group">
<label for="description">Description of Work:</label>
<input name="description' type="text" class="form-control" id="agency" placeholder="Description" />
</div>
<div class="form-group">
<label for="input-date">Enter Today Date</label>
<input name="input-date' type="date" value="">
<span class="result"></span>
</div>
<div class="form-group">
<div class="col-md-10">
<input id="submit" name="submit" type="submit" class="btn btn-primary">
</div>
</div>
</form>
</div>
</div>
and here is my php
<?php
echo $POST;
error_reporting(E_ALL);
ini_set('display_errors', 1);
include("../includes/config.php");
if (isset($_POST['submit'])) {
echo $_POST['submit'];
$name = $_POST['name'];
$projectnum = $_POST['project_num'];
$projectname = $_POST['project_name'];
$easyvista = $_POST['easyvista'];
$agency = $_POST['agency'];
$description = $_POST['description'];
$startDate = $_POST['input-date'];
$sql="INSERT INTO statusreport(name, project_num, project_name, easyvista, agency, description)
VALUES
('$name','$projectnum', '$projectname', '$easyvista', '$agency', '$description')";
if (!mysqli_query($conn, $sql))
{
die('Error: ' . mysqli_connect_error($conn));
}
echo "Entry is recored <br/>";
echo "Name:", $name, "<br/>";
echo "test..................<br/>", $name;
/*header("location: http://10.1.7.129//gisadmin/admin/forms.php");*/
//echo "<script>setTimeout(\"location.href = 'http://10.1.7.129//gisadmin/admin/forms.php';\",700);</script>";
mysqli_query($conn, $sql);
}
else {
echo "No data";
}
?>
Any help would be greatly appreciated.
Thanks
You have a mixing of single and double quotes here, the name attributes are opening the value with double quotes and closing with single quotes, should be as follows:
<form method="post" action="insert.php" >
<div class="form-group">
<label for="name">Name</label>
<input name="name" type="text" class="form-control" id="name" placeholder="Enter your name" required/>
</div>
<div class="form-group">
<label for="project_num">OIT-GIS Project Number</label>
<input name="project_num" type="text" class="form-control" id="project_num" placeholder="OIT-GIS Project Number" />
</div>
<div class="form-group">
<label for="project_name">Project Name</label>
<input name="project_name" type="text" class="form-control" id="project_name" placeholder="Project Name" required/>
</div>
<div class="form-group">
<label for="easyvista">EasyVista Ticket Number</label>
<input name="easyvista" type="text" class="form-control" id="easyvista" placeholder="EasyVista Ticket Number" />
</div>
<div class="form-group">
<label for="agency">Requestor/Agency</label>
<input name="agency" type="text" class="form-control" id="agency" placeholder="Requestor or Agency" />
</div>
<div class="form-group">
<label for="description">Description of Work:</label>
<input name="description" type="text" class="form-control" id="agency" placeholder="Description" />
</div>
<div class="form-group">
<label for="input-date">Enter Today Date</label>
<input name="input-date" type="date" value="">
<span class="result"></span>
</div>
<div class="form-group">
<div class="col-md-10">
<input id="submit" name="submit" type="submit" class="btn btn-primary">
</div>
</div>
</form>
And then, as #Fred -ii stated in his comment, the php script is wrong:
echo $POST;
That line is wrong, there is no variable with name $POST before that code.
Are you getting success message but database is not getting updated OR Getting Total Error...???
1) Check for double quotes and single quotes..
<div class="form-group">
<label for="name">Name</label>
<input name="name" type="text" class="form-control" id="name" placeholder="Enter your name" required/>
</div>
2) Also check for path... for
include("../includes/config.php");
Is it correct or not...?
3)
<label for="project_name">Project Name</label>
<input name="name' type="text"
SHOULD BE
<label for="project_name">Project Name</label>
<input name="project_name" type="text"

Unable to insert row in table using mysqli (PHP)

I am trying to insert a row in a table but its giving me syntax error.
Here is the HTML Code:
<form method="post" action="" >
<!--form fields-->
<div class="control-group">
<div class="customer_data">
<div class="controls" id="id_milesPerDay">
<label for="ICAO" class="left-text">ICAO:</label>
<input type="text" id="ICAO" style='text-transform:uppercase' maxlength="4" name="ICAO" placeholder="" class="input-xlarge" required>
</div>
<div class="controls">
<label for="IATA" class="left-text">IATA:</label>
<input type="text" name="IATA" maxlength="3" style='text-transform:uppercase' id="IATA" placeholder="" class="input-xlarge" required>
</div>
<div class="controls">
<label for="airportname" class="left-text">Airport Name:</label>
<input type="text" name="airport_name" maxlength="" id="Airport_Name" placeholder="" class="input-xlarge" required>
</div>
<div class="controls">
<label for="coordinates" class="left-text">Coordinates:</label>
<input type="text" name="coordinates" maxlength="" id="Coordinates" placeholder="" class="input-xlarge" required>
</div>
<div class="controls">
<label for="Time_zone_UTC" class="left-text">Time Zone UTC:</label>
<input type="text" name="Time_zone_UTC" maxlength="3" id="Time_zone_UTC" placeholder="" class="input-xlarge" required>
</div>
<div class="controls">
<label for="DST" class="left-text">DST:</label>
<input type="checkbox" name="dst" value="other" id="DST" placeholder="" class="input-xlarge">
</div>
<div class="controls text">
<label for="utc" class="left-text">UTC:</label>
<input type="text" name="utc" maxlength="3" id="UTC" placeholder="" class="input-xlarge">
</div>
<div class="controls text">
<label for="From_date" class="left-text">From Date:</label>
<input type="date" name="from_date" maxlength="" id="fromdate" placeholder="" class="input-xlarge">
</div>
<div class="controls text">
<label for="To_date" class="left-text">To Date:</label>
<input type="date" name="to_date" maxlength="" id="todate" placeholder="" class="input-xlarge">
</div>
<!-- Button -->
<div class="control-group">
<div class="controls">
<input type="submit" value="Submit" id="Submit" class="btn btn-success" name="Submit">
</div>
</div>
</div>
<div class="customer_aircraft">
<div class="controls">
<label for="country_code" class="left-text">Country Code:</label>
<input type="text" name="country_code" maxlength="2" style='text-transform:uppercase' id="countrycode" placeholder="" class="input-xlarge" required>
</div>
<div class="controls">
<label for="Remarks" class="left-text">Remarks:</label>
<textarea cols="25" rows="7" name="remarks" id="remarks" placeholder="" class="input-xlarge"></textarea>
</div>
<div class="controls">
<label for="Country" class="left-text">Country: </label>
<input type="text" name="country" maxlength="" id="country" placeholder="" class="input-xlarge" required>
</div>
</div>
</div>
</form>
</body>
</html>
PHP Code:
<?php
$link=require ("Connection.php");
error_reporting(E_ALL); ini_set('display_errors', 1);
if(isset($_POST['Submit']))
{
$ICAO= mysqli_real_escape_string($link,$_POST['ICAO']);
$IATA= mysqli_real_escape_string($link,$_POST['IATA']);
$Airport_Name= mysqli_real_escape_string($link,$_POST['airport_name']);
$coordinates= mysqli_real_escape_string($link,$_POST['coordinates']);
$Time_zone_UTC= mysqli_real_escape_string($link,$_POST['Time_zone_UTC']);
$DST= mysqli_real_escape_string($link,$_POST['dst']);
$UTC= mysqli_real_escape_string($link,$_POST['utc']);
$from_date = mysqli_real_escape_string($link,$_POST['from_date']);
$to_date = mysqli_real_escape_string($link,$_POST['to_date'];
$country_code= mysqli_real_escape_string($link,$_POST['country_code']);
$remarks= mysqli_real_escape_string($link,$_POST['remarks']);
$Country= mysqli_real_escape_string($link,$_POST['country']);
//inserting records//
$sql="INSERT INTO airport_data (ICAO,IATA,Airport_name,Coordinates,Time_zone_utc,DST,UTC,From,To,Country_code,Remarks,Country) VALUES ('$ICAO','$IATA','$Airport_Name','$coordinates','$Time_zone_UTC','$DST','$UTC',STR_TO_DATE('$from_date', '%m/%d/%y'),STR_TO_DATE('$to_date', '%m/%d/%y'),'$country_code','$remarks','$Country')";
if(mysqli_query($link, $sql))
{
echo "Records added successfully.";
}
else
{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// close connection
mysqli_close($link);
}
?>
Here is the error I receive:
ERROR: Could not able to execute INSERT INTO airport_data (ICAO,IATA,Airport_name,Coordinates,Time_zone_utc,DST,UTC,From,To,Country_code,Remarks,Country) VALUES ('oprn','op','islamabad airport','islam','+9','other','+8',STR_TO_DATE('2015-05-26', '%m/%d/%y'),STR_TO_DATE('2015-05-20', '%m/%d/%y'),'op','p','Pakistan'). You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'From,To,Country_code,Remarks,Country) VALUES ('oprn','op','islamabad airport','i' at line 1
Escape (at least) reserved words in column names.
... `From`, `To`, ...
Full list of MySQL reserved words is in http://dev.mysql.com/doc/refman/5.6/en/reserved-words.html.
from and to are reserve keyword. Avoid to use them as column name. You need to change these column name.
You can find more details here
Actually the format of my date variables was wrong so i had to change it like
$from_date = new DateTime($_POST['from_date']);
$to_date = new DateTime($_POST['to_date']);
Insert the following into the database
$from_date = mysqli_real_escape_string($link, $from_date->format('Y-m-d'));
$to_date = mysqli_real_escape_string($link, $to_date->format('Y-m-d'));
And in query
some thing like
,'".$from_date."','".$to_date."',

Categories