mysql - Unable to insert row in table using mysqli (PHP) -
i trying insert row in table giving me syntax error.
here 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 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: not able execute $sql. " . mysqli_error($link); } // close connection mysqli_close($link); } ?>
here error receive:
error: not able execute insert 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'). have error in sql syntax; check manual corresponds mysql server version right syntax use near 'from,to,country_code,remarks,country) values ('oprn','op','islamabad airport','i' @ line 1
escape (at least) reserved words in column names.
... `from`, `to`, ...
full list of mysql reserved words in http://dev.mysql.com/doc/refman/5.6/en/reserved-words.html.
Comments
Post a Comment