Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Wykonujący się kod przed instrukcją
igor1988bb
post
Post #1





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 8.05.2014

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


Witam wszystkich! Bardzo proszę o pomoc gdyż mam mały problem ze swoim kodem. Otóż instrukcja sprawdzająca czy pole tekstowe jest puste wykonuje się zanim przycisnę przycisk. Poniżej wklejam kod. Z góry dziękuję za pomoc i pozdrawiam.

CODE
if(isset ($_POST['upload']))
{
if($_POST['coment'] == NULL)
{
printf("<script>alert('Brak danych!')</script>");
exit();
}
else
{
printf($_POST['coment']);
}
Go to the top of the page
+Quote Post
ilidir
post
Post #2





Grupa: Zarejestrowani
Postów: 183
Pomógł: 14
Dołączył: 27.09.2014

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


Witaj spróbuj coś takiego:

  1. if(empty($_POST['coment']) {
  2. printf("<script>alert('Brak danych!')</script>");
  3. exit();
  4. } else {
  5. printf($_POST['coment']);
  6. }
Go to the top of the page
+Quote Post
igor1988bb
post
Post #3





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 8.05.2014

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


Niestety dalej nie dziala :/. Po odświerzeniu strony dalej wywala ten komunikat.
Go to the top of the page
+Quote Post
Jarma
post
Post #4





Grupa: Zarejestrowani
Postów: 36
Pomógł: 11
Dołączył: 20.07.2009

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


Czyli wyskakuje Ci alert, tak ?

daj na początku kodu
  1. var_dump($_POST)
i napisz co pokazało

Ten post edytował Jarma 6.02.2015, 20:19:42
Go to the top of the page
+Quote Post
igor1988bb
post
Post #5





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 8.05.2014

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


To mi wyskoczyło :

CODE
array (size=3)
'user' => string '' (length=0)
'coment' => string '' (length=0)
'upload' => string 'Ok' (length=2)
Go to the top of the page
+Quote Post
Jarma
post
Post #6





Grupa: Zarejestrowani
Postów: 36
Pomógł: 11
Dołączył: 20.07.2009

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


po naciśnięciu przycisku "ok"?
Go to the top of the page
+Quote Post
igor1988bb
post
Post #7





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 8.05.2014

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


Przed wcisnieciem
Go to the top of the page
+Quote Post
Jarma
post
Post #8





Grupa: Zarejestrowani
Postów: 36
Pomógł: 11
Dołączył: 20.07.2009

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


A przesyłasz do tej strony coś POST'em?
Go to the top of the page
+Quote Post
igor1988bb
post
Post #9





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 8.05.2014

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


Tak i ten post odnosi się do tej samej strony
Go to the top of the page
+Quote Post
Jarma
post
Post #10





Grupa: Zarejestrowani
Postów: 36
Pomógł: 11
Dołączył: 20.07.2009

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


Się trochę zgubiłem, wytłumacz mi jeszcze raz jakie masz strony i co robisz dokładnie.
Go to the top of the page
+Quote Post
igor1988bb
post
Post #11





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 8.05.2014

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


CODE
<html>
<head>
<title>Test</title>
</head>
<body>
<form action= "index.php" method = "post">

<input type="text" name="coment" /><br />
<input type = "submit" name = "upload" value = "Ok">
</form>
<?php


if(isset ($_POST['upload']))
{
var_dump($_POST);
if(empty($_POST['coment']))
{
printf("<script>alert('Brak danych!')</script>");
exit();
}
else
{
printf($_POST['coment']);
}



}




?>
</body>
</html>


Tu jest cały kod. Chodzi mi o to że alert ma wyskakiwać jeśli wcisne ok a pole tekstowe jest puste a wyskakuje mi po odpaleniu i odświeżeniu strony.
Go to the top of the page
+Quote Post
Jarma
post
Post #12





Grupa: Zarejestrowani
Postów: 36
Pomógł: 11
Dołączył: 20.07.2009

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


Postawiłem go u siebie i nic nie wyskakuje przy pierwszym odpaleniu
Go to the top of the page
+Quote Post
igor1988bb
post
Post #13





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 8.05.2014

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


A przy odświeżeniu?
Go to the top of the page
+Quote Post
Jarma
post
Post #14





Grupa: Zarejestrowani
Postów: 36
Pomógł: 11
Dołączył: 20.07.2009

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


Jeżeli odpalę i odświeżę to nic
Go to the top of the page
+Quote Post
igor1988bb
post
Post #15





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 8.05.2014

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


No to niewiem gdzie może leżeć błąd.
Mam wamp server
Go to the top of the page
+Quote Post
Jarma
post
Post #16





Grupa: Zarejestrowani
Postów: 36
Pomógł: 11
Dołączył: 20.07.2009

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


http://screencast.com/t/60mlOXSq8P
Go to the top of the page
+Quote Post
igor1988bb
post
Post #17





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 8.05.2014

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


Już wiem gdzie popełniłem błąd. Przy pierwszym uruchomieniu już wszystko działa i po odświeżeniu strony też było ok. Błąd mi wywalało po przyciśnięciu ok i po ponownym odświeżeniu strony a po wpisaniu tekstu i zatwierdzeniu i po ponownym odświeżeniu już błędu nie było.

Bardzo dziękuję za pomoc!!! (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
Jarma
post
Post #18





Grupa: Zarejestrowani
Postów: 36
Pomógł: 11
Dołączył: 20.07.2009

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


Nie ma za co (IMG:style_emoticons/default/wink.gif)
Go to the top of the page
+Quote Post

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: 19.09.2025 - 11:24