Joa ... ich vermute es ist immer noch der selbe Fehler
Code:
mysql> IF EXISTS(SELECT `type` FROM `words` WHERE `wort`= Value(`wort`)) THEN
BEGIN
UPDATE `words`
SET `type` = Value(`type`), `update` = Value(`update`)
WHERE `wort`= Value(`wort`)
END
ELSE
BEGIN
INSERT INTO `words` (`wort`, `type`, `update`)
VALUES ('ich', 'Pronomen', '1418036206')
END
END IF;
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF EXISTS(SELECT `type` FROM `words` WHERE `wort`= Value(`wort`)) THEN
BEGIN
' at line 1
Ausserhalb von Funktionen kann man die IF Anweisung soweit ich weiß nicht verwenden in MySQL.
Quote:
Originally Posted by Warnuk3r
Quote:
Originally Posted by Mr.Tr33
Joa ... ich vermute es ist immer noch der selbe Fehler
Code:
mysql> IF EXISTS(SELECT `type` FROM `words` WHERE `wort`= Value(`wort`)) THEN
BEGIN
UPDATE `words`
SET `type` = Value(`type`), `update` = Value(`update`)
WHERE `wort`= Value(`wort`)
END
ELSE
BEGIN
INSERT INTO `words` (`wort`, `type`, `update`)
VALUES ('ich', 'Pronomen', '1418036206')
END
END IF;
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF EXISTS(SELECT `type` FROM `words` WHERE `wort`= Value(`wort`)) THEN
BEGIN
' at line 1
Ja und wie wäre es denn dann richtig?
Nach den "Vorlangen" im Link gehts ja auch nicht, wie oben beschrieben.
Wenn ich es nicht selbst herausfinden würde, dann würde ich nicht wohl nach Hilfe fragen.
IF (SELECT `type` NOT NULL FROM `words` WHERE `wort`= Value(`wort`)) THEN
BEGIN
UPDATE `words`
SET `type` = Value(`type`), `update` = Value(`update`)
WHERE `wort`= Value(`wort`)
END
ELSE
BEGIN
INSERT INTO `words` (`wort`, `type`, `update`)
VALUES ('ich', 'Pronomen', '1418036206')
END
END IF;
mysql> IF (SELECT `type` NOT NULL FROM `words` WHERE `wort`= Value(`wort`)) THEN
BEGIN
UPDATE `words`
SET `type` = Value(`type`), `update` = Value(`update`)
WHERE `wort`= Value(`wort`)
END
ELSE
BEGIN
INSERT INTO `words` (`wort`, `type`, `update`)
VALUES ('ich', 'Pronomen', '1418036206')
END
END IF;
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF (SELECT `type` NOT NULL FROM `words` WHERE `wort`= Value(`wort`)) THEN
BEG' at line 1
Wie auf StackOverflow beschrieben lässt sich der IF-Block nicht außerhalb von Funktionen verwenden.
Ich würde empfehlen entweder die wort-Spalte als UNIQUE zu definieren (genauer: zu einem UNIQUE-Index hinzuzufügen), oder tatsächlich mehrere Queries zu verwenden.
Ersteres würde auch helfen, die Integrität der Daten sicherzustellen, da dann unter keinen Umständen ein wort-Wert doppelt eingefügt werden kann.
Code:
ALTER TABLE `words` ADD UNIQUE `wort_index`(`wort`);
Man kann aber ein UNIQUE nicht auf ein text Type setzen. Und meine wort Spalte ist ein text Type.
Wenn es sich bei den Werten für wort um prinzipiell eher kurze Daten handelt (z.B. ein einzelnes Wort), wäre der VARCHAR-Typ evtl. vorzuziehen.
Dieser wird üblicherweise (anders als TEXT und BLOB) "inline" mit der Zeile gespeichert (TEXT und BLOB verwenden Pointer auf extra gespeicherte Werte). Wenn die Performance oder Größe deiner Tabelle nicht durch sehr lange Text-Werte leiden, wäre VARCHAR die bessere Wahl.
Besonders wenn deine Anwendung auch die wort-Spalte zum Selektieren verwendet, wäre ein inline-Typ mit der Möglichkeit zur Indizierung einem nicht indizierbaren, extern gespeicherten Typ vorzuziehen.
PHP / MYSQL Insert REAGIERT NICHT 05/05/2014 - Web Development - 9 Replies Hallo leute,
wollte mittels eines PHP-Scripts Daten in meine Tabelle einfügen.
Es kommt auch keine Fehlermeldung wenn ich bsp. OR DIE ("Fail"); hinzufüge, allerdings
werden die Einträge einfach nicht in die Tabelle übertragen.
Erkennt ihr einen Fehler?
<html>
<head>
<title> Test </title>
MySQL INSERT INTO trägt nicht alle Daten aus Formular ein 08/26/2012 - Web Development - 14 Replies Hallo, ich wollte mir eine kleine Regi basteln.
Dabei stoße ich auf das Problem, dass Username sowie Password eingetragen werden aber die E-Mail nicht. Hier einmal der komplette Code sowie DB:
Das Formular:
<link rel="stylesheet" type="text/css" href="../style.css" />
<h3>Registrierung</h3>
<form action="index.php?page=reg" method="post" id="regist">
<table width="400" border="0" align="center">
<tr>
Mysql 5.5 fehler Account existiert bereits 06/07/2012 - Metin2 Private Server - 6 Replies Hallo
Ich habe seit dem ich Mysql 5.5 benutze den fehler beim hen! cms Account existiert bereits bei jede anmeldung aber account tabelle ist leer bei mysql 5.0 geht alles
[Release] MySQL Insert system 07/18/2010 - CO2 PServer Guides & Releases - 18 Replies Ello!
First of all, this is NOT sourcedependent, which means you can use this on any source without modifying the code.
This is an replacement for all of you who still uses normal MySQL queries. Use this code to clean up, make it easier and more orginazed.
Here's how it looks:
Example: (Original (LOTF for example))
[HELP]C# MySQL Command insert if not exsist? 09/04/2009 - CO2 Private Server - 8 Replies MySqlCommand Command = new MySqlCommand("INSERT INTO accounts(AccountID,LogonType) VALUES ('" + fillBox.Text + "','3')", Connection);
Now, I want it to check if the value of fillBox.Text doesn't excist before making the account, so It wont create the same account. I tried making it in a try, that didn't help, it just make several accounts with the same name.
~Bas