| Autor | Zpráva | ||
|---|---|---|---|
| VIPatrikPK Profil |
#1 · Zasláno: 4. 7. 2013, 21:28:15
Dobrý deň, (už večer :))
mám problém s ktorým si neviem dať rady. Potrebujem nejakým spôsobom aby sa skontroloval e-mail či existuje v databáze keď áno tak sa iba upraví záznam s e-mailom a keď neexistuje tak vytvorenie záznamu s e-mailom, na to som som spravil sql dotaz ktorý ale nefunguje. SQL dotaz: UPDATE `vipatrikpk`.`vpk-rs:registration:before` IF (
(SELECT `vpk-rs:registration:before:e-mail` FROM `vipatrikpk`.`vpk-rs:registration:before` WHERE `vpk-rs:registration:before:e-mail` = '".$_POST['registration:email']."';) == '".$_POST['registration:email']."',
(UPDATE `vipatrikpk`.`vpk-rs:registration:before` SET `vpk-rs:registration:before:ip` = '".$_SERVER['REMOTE_ADDR']."', `vpk-rs:registration:before:time` = '".time()."', `vpk-rs:registration:before:valid` = '1' WHERE `vpk-rs:registration:before:e-mail` = '".$_POST['registration:email']."';),
(INSERT INTO `vipatrikpk`.`vpk-rs:registration:before` (`vpk-rs:registration:before:e-mail`, `vpk-rs:registration:before:ip`, `vpk-rs:registration:before:time`, `vpk-rs:registration:before:valid`) VALUES ('".$_POST['registration:email']."', '".$_SERVER['REMOTE_ADDR']."', '".time()."', '1');)
);Prosím poradte mi a pomôžte mi opraviť chybu ktorá v tom je ďakujem. |
||
| Zechy Profil |
#2 · Zasláno: 4. 7. 2013, 21:38:47
Použij ON DUPLICATE KEY. Na email nastav unikátní klíč, poté stačí napsat prachsprostý insert:
INSERT INTO uzivatel VALUES(email, ip, time, valid) ON DUPLICATE KEY UPDATE email = 'email', ip = 'ip', valid= '1' |
||
| VIPatrikPK Profil |
#3 · Zasláno: 4. 7. 2013, 21:57:42
Keď som správne pochopil tak by to malo fungovať tak ako som ho upravil ale stále mi to nejde :(.
INSERT INTO `vipatrikpk`.`vpk-rs:registration:before` VALUES(`vpk-rs:registration:before:email`, `vpk-rs:registration:before:ip`, `vpk-rs:registration:before:time`, `vpk-rs:registration:before:valid`) ON DUPLICATE KEY UPDATE `vpk-rs:registration:before:email` = '".$_POST['registration:email']."', `vpk-rs:registration:before:ip` = '".$_SERVER['REMOTE_ADDR']."', `vpk-rs:registration:before:time` = '".time()."' `vpk-rs:registration:before:valid` = '1'; |
||
| Tori Profil |
$sql = "INSERT INTO `vipatrikpk`.`vpk-rs:registration:before`
(`vpk-rs:registration:before:email`, `vpk-rs:registration:before:ip`, `vpk-rs:registration:before:time`, `vpk-rs:registration:before:valid`)
VALUES
('".$_POST['registration:email']."', '".$_SERVER['REMOTE_ADDR']."', '".time()."', '1')
ON DUPLICATE KEY UPDATE `vpk-rs:registration:before:email` = VALUES(`vpk-rs:registration:before:email`), `vpk-rs:registration:before:ip` = VALUES(`vpk-rs:registration:before:ip`), `vpk-rs:registration:before:time` = VALUES(`vpk-rs:registration:before:time`) '".time()."', `vpk-rs:registration:before:valid` = '1'"; |
||
|
Časová prodleva: 13 let
|
|||
0