Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Znaki
dareksbs
post
Post #1





Grupa: Zarejestrowani
Postów: 56
Pomógł: 0
Dołączył: 17.10.2012

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


Witam,

Mam problem z dodaniem kodu HTML typu '" do bazy danych, za każdym razem kiedy wpiszę je do formularza następuje błąd dodawania danych do bazy danych

Błąd :
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 '"'

Tak wygląda moje połączenie oraz dodawanie danych do bazy
  1. $connect = @mysql_connect (test,test,test) or die ("ERROR 0001");
  2. mysql_select_db('test') or die ("ERROR 0002");
  3. $query = "INSERT INTO dane VALUES ('', '".$_POST['dane1']."', '".$_POST['dane2']."', '".$_POST['dane3']."'')";
  4. $makeit = mysql_query ($query) or die(mysql_error());
  5. echo"<h1>Informacje dodane</h1>";



Kodu HTML nie będę dodawał bo to zwykły formularz.

Ma ktoś jakiś pomysł jak temu zapobiec

Ten post edytował dareksbs 5.11.2012, 22:20:27
Go to the top of the page
+Quote Post
tab
post
Post #2





Grupa: Zarejestrowani
Postów: 75
Pomógł: 20
Dołączył: 8.10.2012

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


uzyj funkcji addslashes na uploadowanych plikach, a przy ich odczytywaniu uzyj stripslashes

Ten post edytował tab 5.11.2012, 22:22:41
Go to the top of the page
+Quote Post
Spawnm
post
Post #3





Grupa: Moderatorzy
Postów: 4 069
Pomógł: 497
Dołączył: 11.05.2007
Skąd: Warszawa




  1. '".$_POST['dane3']."'')";

Nie za dużo ' przed nawiasem?

@Tab - tak sie tego nie robi.
Poczytaj o mysql_real_escape_string()
Powód edycji: [Spawnm]:
Go to the top of the page
+Quote Post
dareksbs
post
Post #4





Grupa: Zarejestrowani
Postów: 56
Pomógł: 0
Dołączył: 17.10.2012

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


Czyli przykładowo jak bym chciał użyć mysql_real_escape_string to muszę wszystkie posty zamienić na zmienne z tą funkcją coś w stylu

$imie = mysql_real_escape_string($imie),
$nazwisko = mysql_real_escape_string($nazwisko),
$adres = mysql_real_escape_string($adres),
$ksywa = mysql_real_escape_string($ksywa));

i dopiero te zmienne wysyłać na mysql

Ten post edytował dareksbs 5.11.2012, 23:19:47
Go to the top of the page
+Quote Post
tab
post
Post #5





Grupa: Zarejestrowani
Postów: 75
Pomógł: 20
Dołączył: 8.10.2012

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


tak dokładnie
Go to the top of the page
+Quote Post
dareksbs
post
Post #6





Grupa: Zarejestrowani
Postów: 56
Pomógł: 0
Dołączył: 17.10.2012

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


Teraz wysyła pusty formularz...

Zrobiłem coś takiego :

  1. $connect = @mysql_connect (test,test,test) or die ("ERROR 0001");
  2. mysql_select_db('test') or die ("ERROR 0002");
  3. $_POST['dane1'] = mysql_real_escape_string($dane1);
  4. $_POST['dane2'] = mysql_real_escape_string($dane2);
  5. $_POST['dane3'] = mysql_real_escape_string($dane3);
  6. $query = "INSERT INTO dane VALUES ('', '".$dane1."', '".$dane2."', '".$dane3."')";
  7. $makeit = mysql_query ($query) or die(mysql_error());
  8. echo"<h1>Informacje dodane</h1>";
Go to the top of the page
+Quote Post
b4rt3kk
post
Post #7





Grupa: Zarejestrowani
Postów: 1 933
Pomógł: 460
Dołączył: 2.04.2010
Skąd: Lublin

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


Cytat(dareksbs @ 6.11.2012, 00:14:12 ) *
Teraz wysyła pusty formularz...

Zrobiłem coś takiego :

  1. $connect = @mysql_connect (test,test,test) or die ("ERROR 0001");
  2. mysql_select_db('test') or die ("ERROR 0002");
  3. $_POST['dane1'] = mysql_real_escape_string($dane1);
  4. $_POST['dane2'] = mysql_real_escape_string($dane2);
  5. $_POST['dane3'] = mysql_real_escape_string($dane3);
  6. $query = "INSERT INTO dane VALUES ('', '".$dane1."', '".$dane2."', '".$dane3."')";
  7. $makeit = mysql_query ($query) or die(mysql_error());
  8. echo"<h1>Informacje dodane</h1>";


No i nic dziwnego. Zauważ, że przypisujesz wartości do $_POST, a do bazy wpisujesz $dane1, $dane2, $dane3.

  1. $connect = @mysql_connect (test,test,test) or die ("ERROR 0001");
  2. mysql_select_db('test') or die ("ERROR 0002");
  3. $dane1 = mysql_real_escape_string($_POST['dane1']);
  4. $dane2 = mysql_real_escape_string($_POST['dane2']);
  5. $dane3 = mysql_real_escape_string($_POST['dane3']);
  6. $query = "INSERT INTO dane VALUES ('', '".$dane1."', '".$dane2."', '".$dane3."')";
  7. $makeit = mysql_query ($query) or die(mysql_error());
  8. echo"<h1>Informacje dodane</h1>";


Powyższe powinno załatwić sprawę.


--------------------
Jeśli pomogłem, kliknij proszę 'pomógł'. Dzięki.
Go to the top of the page
+Quote Post
dareksbs
post
Post #8





Grupa: Zarejestrowani
Postów: 56
Pomógł: 0
Dołączył: 17.10.2012

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


Cytat(b4rt3kk @ 6.11.2012, 01:29:15 ) *
No i nic dziwnego. Zauważ, że przypisujesz wartości do $_POST, a do bazy wpisujesz $dane1, $dane2, $dane3.

  1. $connect = @mysql_connect (test,test,test) or die ("ERROR 0001");
  2. mysql_select_db('test') or die ("ERROR 0002");
  3. $dane1 = mysql_real_escape_string($_POST['dane1']);
  4. $dane2 = mysql_real_escape_string($_POST['dane2']);
  5. $dane3 = mysql_real_escape_string($_POST['dane3']);
  6. $query = "INSERT INTO dane VALUES ('', '".$dane1."', '".$dane2."', '".$dane3."')";
  7. $makeit = mysql_query ($query) or die(mysql_error());
  8. echo"<h1>Informacje dodane</h1>";


Powyższe powinno załatwić sprawę.


;O hahaha okej, ja już będę szedł spać bo nie myślę ! dzięki za pomoc !
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 22.08.2025 - 06:49