php - MYSQL string to check against multiple fields -
i'm trying check similar entry doesn't exist in database based on 4 pieces of information before inserting new row. it's ok if same name exists example, not if name, lat/long,, , time same. here code:
$query3 = "insert locations ( name, time, area, latitude, longitude, current, previous, destination ) select * ( select name, time, area, latitude, longitude, current, previous, destination) tmp not exists ( select name, latitude, longitude, time locations name = '$name' , latitude = '$latitude' , longitude = '$longitude' , time = '$timereceived') ";
the error pulling
could not connect: unknown column 'name' in 'field list'
i don't understand error message, , i'm thinking have syntax error in mysql string. thank in advance!
your query messed up. using single quotes column names , somewhere using backticks values , somewhere using variables in column name
as in query have used
$name, $timereceived, $area, $latitude, $longitude, $currentport, $previousport, $destination
i guess these variables holding column names if not use column name directly in query
it should like
$query3 = "insert locations ( name, time, area, latitude, longitude, current, previous, destination ) select * ( select $name, $timereceived, $area, $latitude, $longitude, $currentport, $previousport, $destination) tmp not exists ( select name, latitude, longitude, time locations name = '$name' , latitude = '$latitude' , longitude = '$longitude' , time = '$timereceived') ";
update query not correct , missing alias here 1 query should work
insert locations ( name, time, area, latitude, longitude, current, previous, destination ) select * ( select name, time, area, latitude, longitude, current, previous, destination locations )l1 not exists ( select 1 locations l2 l2.name = 'ocean' , l2.latitude = '145.717' , l2.longitude = '-16.6365' , l2.time = '2014-04-23 13:45' );
update2 howard krause has issues of adding data multiple times fix applied as
insert locations (name, area, latitude, longitude, current, previous, destination, time) select a.name, a.area, a.latitude, a.longitude, a.current, a.previous, a.destination, a.time ( select name, area, latitude, longitude, current, previous, destination, time) not exists ( select 1 locations name= '$name' , longitude = '$longitude' );
Comments
Post a Comment