Ich habs schon so wie du. Hier ist die ganze Verarbeitung:
Hierbei ist bei einer eingabe ins erste Feld das wort Elf die $eingabe2:
WHERE dname LIKE %Elf%
und die Fehlermeldung ist:
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 '' WHERE dname LIKE %Elf%'' at line 1
PHP-Code:
if($_POST['dname']!=""){
$ws1=$_POST['dname'];
$w1 = "dname LIKE %$ws1% AND ";
}
if($_POST['ename']!=""){
$ws2=$_POST['ename'];
$w2="ename LIKE %$ws2% AND ";
}
if($_POST['ktext']!=""){
$ws3=$_POST['ktext'];
$w3="text LIKE %$ws3% AND ";
}
if($_POST['atext']!=""){
$ws4=$_POST['atext'];
$w4="anekdote LIKE %$ws4% AND ";
}
if($_POST['katyp']!=""){
$ws5=$_POST['katyp'];
$w5="ktyp LIKE %$ws5% AND ";
}
if($_POST['desi']!=""){
$ws6=$_POST['desi'];
$w6="design LIKE %$ws6% AND ";
}
if($_POST['edition']!=""){
$ws7=$_POST['edition'];
$w7="edition=$ws7 AND ";
}
if($_POST['karart']!=""){
$ws8=$_POST['karart'];
$w8="kartenart=$ws8 AND ";
}
if($_POST['commons']!=""){
$ws9=$_POST['commons'];
$w9="selten=$ws9 AND ";
}
if($_POST['kosten']!="" && $_POST['kostenv']!=""){
$ws10=$_POST['kosten'];
$ws10b=$_POST['kostenv'];
$w10="mkosten$ws10$ws10b AND ";
}
if($_POST['atk']!="" && $_POST['atkv']!=""){
$ws11=$_POST['atk'];
$ws11b=$_POST['atkv'];
$w11="str$ws11$ws11b AND ";
}
if($_POST['def']!="" && $_POST['defv']!=""){
$ws12=$_POST['def'];
$ws12b=$_POST['defv'];
$w12="def$ws12$ws12b AND ";
}
if($_POST['farbe']!=""){
$ws13=$_POST['farbe'];
$w13="farbe=$ws13 AND ";
}
$eingabe=" WHERE $w1$w2$w3$w4$w5$w6$w7$w8$w9$w10$w11$w12$w13";
$zeichen=strlen($eingabe);
$ben_zeichen=$zeichen-5;
$eingabe2=substr($eingabe, 0, $ben_zeichen);
echo "$eingabe2";
// Anzahl aller Karten ermitteln
$result=mysql_query("SELECT COUNT(id) FROM kartendb'$eingabe2'") OR die(mysql_error());
WHERE dname LIKE %Elf%
und die Fehlermeldung ist:
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 '' WHERE dname LIKE %Elf%'' at line 1
Kommentar