sql - mysql error in WHERE clause -
i'm sorry ask such basic question, cant life of me spot error here far can see correct. yet error, perhaps need pair of fresh eyes have look
you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'where event_id = '1243'' @ line 1 in insert expiredevents (event_id,sport_type,tournament,round,team1,team2,venue,event_date) values ('1243','rugby','super15','3','waratahs','sharks','allianz stadium','') event_id = '1243'
$sql="insert expiredevents (event_id,sport_type,tournament,round,team1,team2,venue,event_date) values ('$id','$sport','$trnmnt','$rnd','$t1','$t2','$ven','$edate') event_id = '$id'"
there no where
clause in correct syntax of insert
statement.
depending on want achieve, choose 1 of following.
insert new row, don't bother if 1 having same event_id
exists
insert expiredevents (event_id, sport_type, tournament, round, team1, team2, venue, event_date) values ('$id', '$sport', '$trnmnt', '$rnd', '$t1', '$t2', '$ven', '$edate')
if event_id
unique index
of table expiredevents
, query fails if record having event_id = '$id'
exists.
assuming event_id
pk
of table, keep reading.
insert new row if not exists
insert ignore expiredevents (event_id, sport_type, tournament, round, team1, team2, venue, event_date) values ('$id', '$sport', '$trnmnt', '$rnd', '$t1', '$t2', '$ven', '$edate')
the ignore
keyword turns errors warnings , query completes not insert row if 1 having event_id = '$id'
exists.
inserts row if not exist or update existing one, if exists
insert expiredevents (event_id, sport_type, tournament, round, team1, team2, venue, event_date) values ('$id', '$sport', '$trnmnt', '$rnd', '$t1', '$t2', '$ven', '$edate') on duplicate key update sport_type=values(sport_type), round=round+1, event_date=now()
if row not exist, query insert using values values
clause. if row exists uses on duplicate key update
know how update it. there 3 fields modified in query:
sport_type=values(sport_type)
- value of columnsport_type
updated using value provided in query columnsport_type
(values(sport_type)
,'$sport'
);round=values(round)+1
- value of columnround
updated using current value plus 1 (round+1
); value provided invalues
clause not used;event_date=now()
- value of columnevent_date
modified using value returned functionnow()
; both old value , 1 provided invalues
clause of query ignored.
this example, put there whatever expressions need update existing row.
completely replace existing row new one
replace expiredevents (event_id, sport_type, tournament, round, team1, team2, venue, event_date) values ('$id', '$sport', '$trnmnt', '$rnd', '$t1', '$t2', '$ven', '$edate')
the replace
statement mysql extension sql standard. first delete
s row having event_id = '$id'
(if any) insert
s new row. functionally equivalent delete expiredevents event_id = '$id'
followed first query exposed above in answer.
Comments
Post a Comment