Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP][HTML][MYSQL]Problem z walidacją formularza
-Gość-
post
Post #1





Goście







Witam.

Mam takie problem.

Mam formularz:
  1. form id="comment-form" method="post" action="comment.php">
  2. <label for="comment">Leave a comment: </label><textarea name="comment" id="comment" rows="5" cols="5"></textarea>
  3. <input name="submit" type="submit" id="submit" tabindex="4" value="Send" />
  4. </form>


Jak widać, odnosi się on do pliki comment.php, który wygląda tak:
  1. <?php
  2. $query = mysql_query("insert into comments set news_id='".mysql_real_escape_string($nid)."', type='news', authorid='".mysql_real_escape_string($authorid)."', authorname='".mysql_real_escape_string($authorname)."', date='$date', comment='".mysql_real_escape_string($comment)."'") or die ("MySQL Error: " .mysql_errno(). " in  " . " file: " . __FILE__ . " on line: " . __LINE__);
  3. header("Location: news.php?nid=$nid#comment-".mysql_insert_id()."");
  4. ?>


Teraz mam problem. Nie chcę puścić zapytania jeśli pole jest puste.

No więc mam...
  1. <?php
  2. if((isset($_POST['submit'])) && (empty($comment)))
  3. {
  4.    $error = "Sorry, your comment really shouldn't be empty...";
  5.    header("Location: news.php?nid=$nid#comment-form");
  6. }
  7. ?>


Na stronie news.php mam:
  1. <?php
  2. if(!empty($error))
  3. {
  4. echo $error;
  5. }
  6. ?>


Dlaczego mi nie działa? Siedzę od godziny i nie potrafię znaleść błędu.

Pomożecie?
Go to the top of the page
+Quote Post
-nie-
post
Post #2





Goście







Poczytaj o register globals, czyloi jak przesyłasz dane z forma stosuje tablice superglobalne $_POST
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: 19.08.2025 - 13:36