Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][PHP]Wysyłanie danych przez formularz
Forum PHP.pl > Forum > Przedszkole
mausik
Witajcie, jestem początkujący z php/mysql jeśli chodzi o pisanie własnych skryptów.
Html znam offtopic.gif .

Mam 3pliki.

Wyswietl.php
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-type" content="text/html; charset=windows-1250">
  4. <title>Wybór bazy</title></head>
  5. </html>
  6. <?
  7. @$db = mysql_pconnect("localhost", "mausik_test", "haslo");
  8. $wyborbazy=@mysql_select_db("mausik_test");
  9. $query = "select * from prezenterzy";
  10. $result = mysql_query($query);
  11. $num_results =mysql_num_rows($result);
  12.  
  13. print "<p>Ilość prezenterów w bazie danych: ".$num_results."</p>";
  14. for ($i=0; $i <$num_results; $i++) {
  15. $row = mysql_fetch_array($result);
  16. print stripslashes($row["imie"] );
  17. print "<br>";
  18. print stripslashes($row["ksywka"] );
  19. print "<br>";
  20. print stripslashes($row["stanowisko"] );
  21. print "<br>";
  22. print stripslashes($row["gg"] );
  23. print "<br>";
  24. print "<br>";
  25. }
  26. ?>
  27.  


nowyprezenter.html

  1. <form action="nowyprezenter.php" method="post">
  2.  
  3.  
  4. Imię prezentera:<input type=text name="imie" maxlength=20 size=15><br>
  5. Ksywka prezentera: <input type=text name="ksywka" maxlength=30 size=20><br>
  6. Stanowisko: <input type=text name="stanowisko" maxlength=20 size=20><br>
  7. GG:<input type=text name="gg" maxlength=9 size=15><br>
  8. <input type=submit value="Wstaw do bazy">
  9.  
  10.  
  11.  
  12. </form>


nowyprezenter.php

  1. <html>
  2. <head>
  3. <meta http-equiv="Content-type" content="text/html; charset=windows-1250">
  4. <title>Dodawanie ...</title></head>
  5. </html>
  6. <?
  7. if (!imie || !$ksywka || !$stanowisko || !$gg)
  8.  
  9. {
  10. print "nie zostały wypelnione wszystkie pola";
  11. }
  12. $imie = addslashes($imie);
  13. $ksywka = addslashes($ksywka);
  14. $stanowisko = addslashes($stanowisko);
  15. $gg = addslashes($gg);
  16.  
  17. @ $db = mysql_pconnect("localhost", "mausik_test", "haslo");
  18. mysql_select_db("mausik_test");
  19.  
  20. $query = "insert into prezenterzy values ('".$imie."', '".$ksywka."', '".$stanowisko."', '".$gg."')";
  21. $result = mysql_query($query);
  22.  
  23. if ($result)
  24. print "Towar <b> ".$imie."</b> został dodany do bazy danych. <br> <a href='nowyprezenter.html'>wróć</a>";
  25. else { print "W bazie istnieje już produkt o tym numerze.";}
  26. ?>


Problem polega na tym, że skrypt po wpisaniu tylko 3tabelek w formularzu powinien zwrócić 'nie zostały wypelnione wszystkie pola' jednak tak nie jest... Dalej, nie wysyła danych do bazy, a wyświetla "Towar został dodany do bazy danych. wróć".

Co robię nie tak, czekam na waszą pomoc.
Pozdrawiam
r4xz
if (!imie || !$ksywka || !$stanowisko || !$gg)

($imie)



pokaż jak wygląda twoja tabela w bazie, może zapomniałeś jakiejś wartości podać przy zapytaniu?

guilty82
  1. if (!isset($_POST['imie']) || !isset($_POST['ksywka']) || !isset($_POST['stanowisko']) || !isset($_POST['gg']))

mausik
r4xz poprawiłem i
Cytat
nie zostały wypelnione wszystkie pola
chodź wszystkie są wypełnione.. smile.gif

Tabela: http://magicradio.pl/upload/index.php?id=21

guilty82 <- nic nie dało..

f5... proszę dalej o pomoc...

f5
Wicepsik
Jak zmieniałeś w ifie na $_POST to tutaj też zmieniłeś ?
  1. addslashes($imie);
  2. addslashes($_POST['imie']);
mausik
Dzięki, poszło. Moje pliki wyglądają teraz:
nowyprezetner.php
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-type" content="text/html; charset=windows-1250">
  4. <title>Dodawanie ...</title></head>
  5. </html>
  6. <?
  7. if (!isset($_POST['imie']) || !isset($_POST['ksywka']) || !isset($_POST['stanowisko']) || !isset($_POST['gg']))
  8.  
  9. {
  10. print "nie zostały wypelnione wszystkie pola";
  11. }
  12. $imie = addslashes($_POST['imie']);
  13. $ksywka = addslashes($_POST['ksywka']);
  14. $stanowisko = addslashes($_POST['stanowisko']);
  15. $gg = addslashes($_POST['gg']);
  16.  
  17. @ $db = mysql_pconnect("localhost", "mausik_test", "123123");
  18. mysql_select_db("mausik_test");
  19.  
  20. $query = "insert into prezenterzy values ('".$imie."', '".$ksywka."', '".$stanowisko."', '".$gg."')";
  21. $result = mysql_query($query);
  22.  
  23. if ($result)
  24. print "Towar <b> ".$imie."</b> został dodany do bazy danych. <br> <a href='nowyprezenter.html'>wróć</a>";
  25. else { print "W bazie istnieje już produkt o tym numerze.";}
  26. ?>


wyborbazy.php

  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  4. <meta http-equiv="Reply-to" content="maaauus@o2.pl">
  5. <meta http-equiv="Content-Language" content="pl">
  6. <meta name="Description" content="Ekipa radia -panel dodawnia/usuwania">
  7. <meta name="Author" content="maus">
  8. <title>Prezenterzy</title></head>
  9. <body bgcolor="#032234" text="#fffff">
  10. <center>
  11. <?
  12. @$db = mysql_pconnect("localhost", "mausik_test", "123123");
  13. $mysqli->set_charset("utf8");
  14. $wyborbazy=@mysql_select_db("mausik_test");
  15. $query = "select * from prezenterzy";
  16. $result = mysql_query($query);
  17. $num_results =mysql_num_rows($result);
  18.  
  19. print "<p>Ilość prezenterów w bazie danych: ".$num_results."</p>";
  20. for ($i=0; $i <$num_results; $i++) {
  21. $row = mysql_fetch_array($result);
  22. print stripslashes($row["imie"] );
  23. print "<br>";
  24. print stripslashes($row["ksywka"] );
  25. print "<br>";
  26. print stripslashes($row["stanowisko"] );
  27. print "<br>";
  28. print stripslashes($row["gg"] );
  29. print "<br>";
  30. print "<br>";
  31. }
  32. ?>
  33.  
  34.  
  35.  
  36.  
  37.  
  38. </body>
  39. </html>


nowyprezenter.html

  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  4. <meta http-equiv="Reply-to" content="maaauus@o2.pl">
  5. <meta http-equiv="Content-Language" content="pl">
  6. <meta name="Description" content="Ekipa radia -panel dodawnia/usuwania">
  7. <meta name="Author" content="maus">
  8. <title>Dodawanie</title></head>
  9. <body bgcolor="#032234" text="#fffff">
  10. <center><br><br>
  11. Co chcesz zrobić?<br>
  12. <a href="#">Dodaj prezentera</a> <a href="#">Usuń prezentera</a> <a href="#">Wyloguj prezentera</a><br><br>
  13. <form action="nowyprezenter.php" method="post">
  14.  
  15.  
  16. Imię prezentera:<input type=text name="imie" maxlength=20 size=15><br>
  17. Ksywka prezentera: <input type=text name="ksywka" maxlength=30 size=20><br>
  18. Stanowisko: <input type=text name="stanowisko" maxlength=20 size=20><br>
  19. GG:<input type=text name="gg" maxlength=9 size=15><br>
  20. <input type=submit value="Wstaw do bazy">
  21.  
  22.  
  23.  
  24. </form>
  25.  
  26.  
  27.  
  28.  
  29.  
  30. </body>
  31. </html>


Co muszę zrobić żeby:
a) łączenie z bazą było w pliku config.php ? jak ten plik powinien wyglądąć
cool.gif jakiś panel z logowaniem do tego? - czyli index.php i po poprawnym zalogowaniu przejście do nowyprezenter.html

Pozdro!
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.