Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Znaki
dareksbs
post 5.11.2012, 22:15:20
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
 
Start new topic
Odpowiedzi
dareksbs
post 6.11.2012, 00:14:12
Post #2





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 6.11.2012, 00:29:15
Post #3





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

Posty w temacie


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 Wersja Lo-Fi Aktualny czas: 14.08.2025 - 20:34