Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][MySQL] Warunek dodanie do bazy
tenloginjestzaje...
post
Post #1





Grupa: Zarejestrowani
Postów: 358
Pomógł: 1
Dołączył: 20.07.2014

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


Witam
Przycisk wstawia do pola input numer id jeżeli pole to jest puste to chciałbym, aby dodano do innej tablicy w bazie. Robię tak jednak bez efektu.

  1. <?php
  2. if($_POST['id'] == '')
  3. if(isset($_POST['comment'])){
  4. $comment = mysql_real_escape_string($_POST['comment']);
  5. $mail = mysql_real_escape_string($_POST['mail']);
  6. $top = mysql_real_escape_string($_POST['id']);
  7. $time = mktime();
  8. mysql_query("INSERT INTO `answer` SET `top` = '$top', `time` = '$time', `content` = '$comment', `tag` = '$tag', `mail` = '$mail'");
  9. echo 'answer';
  10. }
  11. else {
  12. if(isset($_POST['comment'])){
  13. $comment = mysql_real_escape_string($_POST['comment']);
  14. $mail = mysql_real_escape_string($_POST['mail']);
  15. $time = mktime();
  16. mysql_query("INSERT INTO `rewievs` SET `time` = '$time', `content` = '$comment', `tag` = '$tag', `mail` = '$mail'");echo 'rewievs';
  17. }
  18. }
  19. ?>


Jeszcze mam problem z przesunięciem strony po kliknięciu do formularza ( dół strony ). Nie wiem jak zastosować kotwicę w przycisku (#kotwica ). Dziękuje

  1. <input class="format" type="button" value="odpowiedz" onclick="wpisz('.$id.');">
  2. <input type="text" class="szukaj" id="id" name="id" value="" />
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
tenloginjestzaje...
post
Post #2





Grupa: Zarejestrowani
Postów: 358
Pomógł: 1
Dołączył: 20.07.2014

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


bardzo dziękuje za pomoc! Działa
  1. <?php
  2. var_dump($_POST);
  3. if(empty($_POST['id'])){
  4. if(isset($_POST['description'])){
  5. $comment = mysql_real_escape_string($_POST['description']);
  6. $mail = mysql_real_escape_string($_POST['mail']);
  7. $time = mktime();
  8. mysql_query("INSERT INTO `rewievs` SET `time` = '$time', `content` = '$comment', `tag` = '$tag', `mail` = '$mail'"); echo 'rewievs';
  9. }
  10. }
  11. else
  12. {
  13. if(isset($_POST['description'])){
  14. $comment = mysql_real_escape_string($_POST['description']);
  15. $mail = mysql_real_escape_string($_POST['mail']);
  16. $top = mysql_real_escape_string($_POST['id']);
  17. $time = mktime();
  18. mysql_query("INSERT INTO `answer` SET `time` = '$time', `top` = '$top', `content` = '$comment', `tag` = '$tag', `mail` = '$mail'"); echo 'answer';
  19. }
  20. }
  21. ?>


Jeszcze tylko odnośnie zejścia na dół do formularza po kliknięciu (#kotwica ) w input button. Jest taka możliwość?

  1. <input class="format" type="button" value="odpowiedz" onclick="wpisz('.$id.');">
  2. <input type="text" class="szukaj" id="id" name="id" value="" />


Ten post edytował tenloginjestzajety 23.04.2016, 21:25:18
Go to the top of the page
+Quote Post

Posty w temacie


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: 26.12.2025 - 02:37