MySQL syntax error inserting php strings into table -


i'm parsing website's table querypath , trying put results mysql database. table looks this:

mysql_query("create table airplanes (     flightid varchar( 50 ) primary key not null,      flightlink text( 20000 ) not null,     orig text( 20 )  not  null,     dest varchar( 20 )  not  null ,     time varchar( 5 )  not  null ); "); 

i trying save airplanes using flight numbers ids.

this how extract table , echos shoving variables' contents.

        $flightdata = $row->find('td');         // $flightid = str_replace(" ", "", $flightdata->eq(1)->text());         $flightid = mysql_real_escape_string( trim( $flightdata->eq(1)->text() ) );         $flightlink = mysql_real_escape_string( $flightdata->eq(1)->html() );         $orig = mysql_real_escape_string( "rome (fco)" );         $dest = mysql_real_escape_string( trim( $flightdata->eq(2)->text() ) );         $time = mysql_real_escape_string( trim( $flightdata->eq(4)->text() ) );          echo '$flightid: ';         echo var_dump($flightid)."<br>";         echo '$orig: ';         echo var_dump($orig)."<br>";         echo '$dest: ';         echo var_dump($dest)."<br>";         echo '$time: ';         echo var_dump($time)."<br>"; 

didn't ask echo $flightlink, have been pretty long. output on variables:

$flightid: string(7) "jn 5215" $orig: string(10) "rome (fco)" $dest: string(14) "tel aviv (tlv)" $time: string(5) "23:45"  

this sql-query:

        $insertquery = mysql_query("insert airplanes (flightid, flightlink, orig, dest, time) values( '$flightid', '$flightlink', '$orig', '$dest', '$time' ) on duplicate key update;");         if($insertquery == false) die("problem inserting flight data table. ".mysql_error($connection)); 

and error message on input query:

problem inserting flight data table. have error in sql syntax;  check manual corresponds mysql server version right syntax use near '' @ line 1 

i've seen loads of other guys having trouble feeding mysql strings, of them failed on quotation marks, bet it's gonna that. still couldn't find though. grateful feedback on improving mysql-table, getting , not sure data types.

your insert ... on duplicate key update syntax invalid because have tell columns want update when duplicate encountered

insert airplanes (flightid, flightlink, orig, dest, time)  values( '$flightid', '$flightlink', '$orig', '$dest', '$time' )  on duplicate key update                        ^^^^ missing part of on duplicate clause 

it should

insert airplanes (flightid, flightlink, orig, dest, time)  values( '$flightid', '$flightlink', '$orig', '$dest', '$time' )  on duplicate key update flightlink = values(flightlink),                                orig = values(orig),                               dest = values(dest),                               time = values(time) 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -