Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][PHP]Dodawanie do bazy problem
Forum PHP.pl > Forum > Przedszkole
Lampek
Witam
Robię właśnie prosty system newsów na stronkę. Mój problem polega na tym że za każdym razem jak z menu wybiorę dodaj newsa to automatycznie do bazy dodaje się pole "autor" i data dodania i nie wiem dla czego, np odświeżę sobie zakładkę dodaj to 5 razy do razy automatycznie doda mi się do pola autor pięć rekordów o wartość "autora" a do pola data pięć rekordów "data bieżąca".

dodaj.php

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6.  
  7. <script src="elrte/js/jquery-1.4.4.min.js" type="text/javascript" charset="utf-8"></script>
  8. <script src="elrte/js/jquery-ui-1.8.7.custom.min.js" type="text/javascript" charset="utf-8"></script>
  9. <link rel="stylesheet" href="elrte/css/smoothness/jquery-ui-1.8.7.custom.css" type="text/css" media="screen" charset="utf-8">
  10.  
  11. <!-- elRTE -->
  12. <script src="elrte/js/elrte.min.js" type="text/javascript" charset="utf-8"></script>
  13. <link rel="stylesheet" href="elrte/css/elrte.min.css" type="text/css" media="screen" charset="utf-8">
  14.  
  15. <!-- elFinder -->
  16. <link rel="stylesheet" href="elrte/css/elfinder.css" type="text/css" media="screen" charset="utf-8" />
  17. <script src="elrte/js/elfinder.full.js" type="text/javascript" charset="utf-8"></script>
  18. <script src="elrte/js/i18n/elrte.pl.js" type="text/javascript" charset="utf-8"></script>
  19. <script src="elrte/js/i18n/elfinder.pl.js" type="text/javascript" charset="utf-8"></script>
  20. <!-- elRTE and elFinder translation messages -->
  21. <!--<script src="js/i18n/elrte.ru.js" type="text/javascript" charset="utf-8"></script>
  22. <script src="js/i18n/elfinder.ru.js" type="text/javascript" charset="utf-8"></script>-->
  23.  
  24. <script type="text/javascript" charset="utf-8">
  25. // elRTE with elFinder on a textarea
  26. $().ready(function() {
  27. var opts = {
  28. cssClass : 'el-rte',
  29. lang : 'pl', // Set your language
  30. allowSource : 1,
  31. height : 450,
  32. toolbar : 'maxi', // 'tiny', 'compact', 'normal', 'complete', 'maxi', or 'custom' (see advanced documentation for 'custom')
  33. cssfiles : ['elrte/css/elrte-inner.css'],
  34. fmAllow : 1,
  35. fmOpen : function(callback) {
  36. $('<div id="myelfinder" />').elfinder({
  37. url : 'elrte/connectors/php/connector.php',
  38. places : '',
  39. lang : 'pl', //Set your language
  40. dialog : { width : 900, modal : true, title : 'Files' }, // Open in dialog window
  41. closeOnEditorCallback : true, // Close after file select
  42. editorCallback : callback // Pass callback to file manager
  43. })
  44. }
  45.  
  46. }
  47. $('#editor').elrte(opts);
  48. // Text field with elFinder
  49. var opt = {
  50. url : 'elrte/connectors/php/connector.php',
  51. places : '',
  52. lang : 'pl',
  53. editorCallback : function(url) {document.getElementById('field').value=url;}, // The id of the field we want elfinder to return a value to.
  54. closeOnEditorCallback : true,
  55. docked : false,
  56. dialog : { title : 'File Manager', height: 500 },
  57. }
  58.  
  59. $('#open').click(function() { // The id of the button that opens elfinder
  60. $('#finder').elfinder(opt) // The id of the div that elfinder will open in
  61. $('#finder').elfinder($(this).attr('id')); // It also has to be entered here.
  62. })
  63. // Second text field with elFinder
  64. var opt2 = { //Must change variable name
  65. url : 'elrte/connectors/php/connector.php',
  66. places : '',
  67. lang : 'pl',
  68. editorCallback : function(url) {document.getElementById('field2').value=url;}, //Must change the text field id
  69. closeOnEditorCallback : true,
  70. docked : false,
  71. dialog : { title : 'File Manager', height: 500 },
  72. }
  73.  
  74. $('#open2').click(function() { //Must change the button id
  75. $('#finder2').elfinder(opt2) //Must update the div id
  76. $('#finder2').elfinder($(this).attr('id')); //Must update the div id
  77. })
  78. })
  79. </script>
  80.  
  81. </head>
  82. <body>
  83. <?php
  84.  
  85. include("polacz.php");
  86. $query = mysql_query("insert into news values('','".$_POST['tytul']."',now(),'".$_POST['autor']."','".$_POST['tresc']."')");
  87. ?>
  88. <form action="" method="post">
  89. Tytuł(maksymalnie 100 znaków): <input type="text" name="tytul">
  90. <br/>Autor(maksymalnie 30 znaków) <input type="text" name="autor">
  91. <br/>Treść <textarea id="editor" name="tresc"></textarea>
  92. <br/><input type="submit" value="Dodaj"></form>
  93.  
  94.  
  95. </body>
  96. </html>
Majkelo23
Dziwisz się? Musisz zdefiniować co ma się dziać, przed wysłaniem formularza i po wysłaniu formularza, ty wszystko wysyłasz od razu. Przykład jak ma to wyglądać:

  1. if ( !isset($_POST['submit']) )
  2. {
  3. $body = '<form action="index.php" method="post"><input type="post" name="imie"><br><input type="submit" name="submit"></form>';
  4. echo $body;
  5. }
  6. else if ( isset($_POST['submit']) )
  7. {
  8. $sql = "INSERT INTO `tabela` (`imie`) VALUES ('".$_POST['imie']."')";
  9. $result = mysql_query($sql)
  10. or die("blad");
  11. echo "dane zapisane!";
  12. }
Lampek
Dzięki wszystko śmiga smile.gif ps nie ma to jak głupie błędy nowicjusza smile.gif
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.