Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL][PHP]Problem z wypisaniem zmiennej
pdg1264
post 12.10.2014, 17:30:09
Post #1





Grupa: Zarejestrowani
Postów: 41
Pomógł: 1
Dołączył: 17.05.2014

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


Mam problem z wypisaniem zmiennej

Chcę wyświetlić to
  1. $tresc = mysqli_real_escape_string($con, $_GET['tresc']);


Tutaj
  1. echo"<td><textarea name='tresc' cols='30' rows='20'>".$tresc."</textarea></td>";


próbowałem tak

  1. $_POST["tresc"]
  2. $tresc



cały kod
  1. <?php
  2. $con=mysqli_connect("localhost","root","pass","strona");
  3. // sprawdz polaczenie
  4. if (mysqli_connect_errno()) {
  5. echo "Błąd podczas łączenia z bazą danych: " . mysqli_connect_error();
  6. }
  7. $result = mysqli_query($con,"SELECT * FROM newsy");
  8.  
  9. $tytul = mysqli_real_escape_string($con, $_GET['tytul']);
  10. $tytulglowna = mysqli_real_escape_string($con, $_GET['tytulglowna']);
  11. $tresc = mysqli_real_escape_string($con, $_GET['tresc']);
  12.  
  13. echo"<table>";
  14. echo"<form action='update.php' method='post'>";
  15. echo"<tr>";
  16. echo"<td><p><h3>Edycja Newsa</h3></p><hr></td>";
  17. echo"</tr>";
  18. echo"<tr>";
  19. echo"<td>Tytuł</td>";
  20. echo"<td><input type='text' name='tytul' size='25' maxlength='32'/></td>";
  21. echo"</tr>";
  22. echo"<tr>";
  23. echo"<td>Tytuł na stronę głowną</td>";
  24. echo"<td><input type='text' name='tytulglowna' size='25' maxlength='20' value=''/></td>";
  25. echo"</tr>";
  26. echo"<tr>";
  27. echo"<td>Treść</td>";
  28. echo"<td><textarea name='tresc' cols='30' rows='20'>".$tresc."</textarea></td>";
  29. echo"</tr>";
  30. echo"<tr>";
  31. echo"<td><input type='submit'/></td>";
  32. echo"</tr>";
  33. echo"</form>";
  34. echo"</table>";
  35. echo"</div>";
  36.  
  37. mysqli_close($con);


Ten post edytował pdg1264 12.10.2014, 17:33:02
Go to the top of the page
+Quote Post
Forti
post 12.10.2014, 17:36:24
Post #2





Grupa: Zarejestrowani
Postów: 655
Pomógł: 73
Dołączył: 2.05.2014

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


1. Podstawy.
2. twój formularz wysyła Cie do pliku update.php ;]
3.:


  1. if (formularz wysłano)
  2. {
  3. //....
  4. }
  5. else
  6. {
  7. //wyświetl formularz
  8. }


Ten post edytował Forti 12.10.2014, 17:37:15


--------------------
Overwatch24 - najbardziej zaawansowany Polski portal Overwatch od fanów dla fanów.

Fachowo.co

Behance.net/fachowo
Go to the top of the page
+Quote Post
pdg1264
post 12.10.2014, 17:37:39
Post #3





Grupa: Zarejestrowani
Postów: 41
Pomógł: 1
Dołączył: 17.05.2014

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



Update.php
  1. <?php
  2. $con=mysqli_connect("localhost","root","pass","strona");
  3. // Check connection
  4. if (mysqli_connect_errno()) {
  5. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  6. }
  7.  
  8. // escape variables for security
  9. $tytul = mysqli_real_escape_string($con, $_POST['tytul']);
  10. $tytulglowna = mysqli_real_escape_string($con, $_POST['tytulglowna']);
  11. $tresc = mysqli_real_escape_string($con, $_POST['tresc']);
  12.  
  13. $sql="UPDATE newsy (tytul, tytulglowna, tresc)
  14. VALUES ('$tytul', '$tytulglowna', '$tresc')";
  15.  
  16. if (!mysqli_query($con,$sql)) {
  17. die('Error: ' . mysqli_error($con));
  18. }
  19.  
  20. mysqli_close($con);
  21. ?>
Go to the top of the page
+Quote Post
Forti
post 12.10.2014, 17:41:44
Post #4





Grupa: Zarejestrowani
Postów: 655
Pomógł: 73
Dołączył: 2.05.2014

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


I teraz podsumowanie:

klepiesz w formularzy dane i klikasz przycisk. Co się dzieje? ;]


--------------------
Overwatch24 - najbardziej zaawansowany Polski portal Overwatch od fanów dla fanów.

Fachowo.co

Behance.net/fachowo
Go to the top of the page
+Quote Post
pdg1264
post 12.10.2014, 17:44:48
Post #5





Grupa: Zarejestrowani
Postów: 41
Pomógł: 1
Dołączył: 17.05.2014

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


I wywala error

  1. Error: 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 '(tytul, tytulglowna, tresc) VALUES ('tes2222', 'sad', 'asdasdas')' at line 1
Go to the top of the page
+Quote Post
Pyton_000
post 12.10.2014, 17:48:51
Post #6





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

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


http://dev.mysql.com/doc/refman/5.0/en/update.html
Go to the top of the page
+Quote Post
pdg1264
post 12.10.2014, 17:50:45
Post #7





Grupa: Zarejestrowani
Postów: 41
Pomógł: 1
Dołączył: 17.05.2014

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


Dzięki przyda się.

Ja korzystałem z tego http://www.w3schools.com/php/php_mysql_update.asp

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 Wersja Lo-Fi Aktualny czas: 12.07.2025 - 20:40