Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]preg_match i apostrof
djtomaszq
post
Post #1





Grupa: Zarejestrowani
Postów: 192
Pomógł: 0
Dołączył: 5.07.2015

Ostrzeżenie: (0%)
-----


Używam sprawdzenia w rejestracji:
  1. if(!preg_match("@^[a-zA-Z0-9_-]+$@",$login))
  2. {
  3. $flaga = false;
  4. }


używam zmiennej login w zapytaniu
  1. $rezultat = $polaczenie->query("SELECT id_users FROM users WHERE login = '$login'");


Jak wpisze w loginie string z apostrofem w liczbie pazystej wyskakuje:
  1. Exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'd'dsd'' at line 1 in


Czy preg_match przepuszcza apostrofy czy czegoś nie rozumiem ? (Pewnie to drugie).
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 559
Pomógł: 6315
Dołączył: 27.12.2004




1) Na chwile obecna nigdzie nie sprawdzasz czy $flaga to true czy false.
2)
nie [a-zA-Z0-9_-]
a [a-zA-Z0-9_\-]
- to znak specjalny.

3) Dane wkladane to zapytania tak czy siak wypadaloby by ESCAPOWAC a juz najlepiej BINDowac.
Go to the top of the page
+Quote Post
Pyton_000
post
Post #3





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


Cytat(nospor @ 19.09.2016, 10:52:44 ) *
2)
nie [a-zA-Z0-9_-]
a [a-zA-Z0-9_\-]
- to znak specjalny.


Może się czepam ale nie jeśli występuje na końcu (IMG:style_emoticons/default/wink.gif)

Cytat
The minus (hyphen) character can be used to specify a range of characters in a character class. For example, [d-m] matches any letter between d and m, inclusive. If a minus character is required in a class, it must be escaped with a backslash or appear in a position where it cannot be interpreted as indicating a range, typically as the first or last character in the class.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 8.10.2025 - 22:39