2016-04-03 41 views
1

我使用PHP和mysqli,在這個例子中,我試圖更新價格,如果數據庫中存在usernamelastname,否則我想插入一個新用戶。爲什麼這不起作用?MYSQL插入/更新,如果其他語句

IF (SELECT name,lastname FROM peoplePrice WHERE name='gus' AND lastname='lw') THEN 
    UPDATE peoplePrice SET price='20' WHERE name='gus' AND lastname='lw'; 
ELSE 
    INSERT INTO peoplePrice (name,lastname,price) 
    VALUES ('nisse','johansson','20'); 
END IF; 
+1

'SELECT'返回行。看看http://stackoverflow.com/questions/4205181/insert-into-a-mysql-table-or-update-if-exists –

+0

嘗試使用SELECT COUNT(*)而不是 –

+0

你只是插入一個隨機用戶,或者'name'和'lastname'匹配'SELECT'中使用的名稱? – Arjan

回答