Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Gdzie jest błąd? pętle
shpaque
post
Post #1





Grupa: Zarejestrowani
Postów: 651
Pomógł: 3
Dołączył: 31.01.2011
Skąd: Warszawa

Ostrzeżenie: (10%)
X----


nie zapisuje plików z formularza, co więcej czysci cały plik csv

  1. <?php
  2.  
  3. ini_set("display_errors", 1);
  4.  
  5. $getdate = $_GET['datein'];
  6. $getcity = $_GET['city'];
  7.  
  8. $dateins = array();
  9. $dateouts = array();
  10. $titles = array();
  11. $programs = array();
  12. $citys = array();
  13. $streets = array();
  14. $places = array();
  15. $seats = array();
  16. $userss = array();
  17.  
  18. $database = './../db/events.csv';
  19. $items = file($database);
  20. $count = 0;
  21. $kodindex = -1;
  22. foreach($items as $line)
  23. {
  24. list($datein, $dateout, $title, $program, $city, $street, $place, $seat, $users) = explode('|', trim($line));
  25. $dateins[$count] = $datein;
  26. $dateouts[$count] = $dateout;
  27. $titles[$count] = $title;
  28. $programs[$count] = $program;
  29. $citys[$count] = $city;
  30. $streets[$count] = $street;
  31. $places[$count] = $place;
  32. $seats[$count] = $seat;
  33. $userss[$count] = $users;
  34.  
  35. if ($getdate == $datein && $getcity == $city)
  36. {
  37. $kodindex = $count;
  38. }
  39. $count++;
  40. }
  41. $file = fopen($database, 'r');
  42. for ($i = 0; $i < $count; $i++)
  43. {
  44. if ($i == $kodindex)
  45. {
  46. $datein = $dateins[$i];
  47. $dateout = $dateouts[$i];
  48. $title = $titles[$i];
  49. $program = $programs[$i];
  50. $city = $citys[$i];
  51. $street = $streets[$i];
  52. $place = $places[$i];
  53. $seat = $seats[$i];
  54. $users = $userss[$i];
  55. }
  56. }
  57. fclose($file);
  58.  
  59. if ($_SERVER['REQUEST_METHOD'] == 'POST')
  60. {
  61. $action = isset($_POST['action']) ? $_POST['action'] : '';
  62. if ($action == "update")
  63. {
  64. $newdatein = $_POST['datein'];
  65. $newdateout = $_POST['dateout'];
  66. $newtitle = $_POST['title'];
  67. $newprogram = $_POST['program'];
  68. $newcity = $_POST['city'];
  69. $newstreet = $_POST['street'];
  70. $newplace = $_POST['place'];
  71. $newseat = $_POST['seat'];
  72. $newusers = implode(',', $user[$x]);
  73.  
  74. $file = fopen($database, 'w');
  75. for ($z = 0; $z < $count; $z++)
  76. {
  77. if ($z == $i)
  78. {
  79. fwrite($file, "".$newdatein."|".$newdateout."|".$newtitle."|".$newprogram."|".$newcity."|".$newstreet."|".$newplace."|".$newseat."|".$$newusers."\r\n");
  80. }
  81. }
  82. fclose($file);
  83. header('Location: admin.php');
  84. }
  85. }
  86. ?>


wywala tak:

[htmlNotice: Undefined index: datein in /home/smusic/ftp/_uniwersytetrodzica/php/admin-edit.php on line 67

Notice: Undefined index: dateout in /home/smusic/ftp/_uniwersytetrodzica/php/admin-edit.php on line 68

Notice: Undefined index: title in /home/smusic/ftp/_uniwersytetrodzica/php/admin-edit.php on line 69

Notice: Undefined variable: x in /home/smusic/ftp/_uniwersytetrodzica/php/admin-edit.php on line 75

Notice: Undefined index: in /home/smusic/ftp/_uniwersytetrodzica/php/admin-edit.php on line 75

Warning: implode() [function.implode]: Invalid arguments passed in /home/smusic/ftp/_uniwersytetrodzica/php/admin-edit.php on line 75

Warning: Cannot modify header information - headers already sent by (output started at /home/smusic/ftp/_uniwersytetrodzica/admin/aedit.php:37) in /home/smusic/ftp/_uniwersytetrodzica/php/admin-edit.php on line 86[/html]
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
shpaque
post
Post #2





Grupa: Zarejestrowani
Postów: 651
Pomógł: 3
Dołączył: 31.01.2011
Skąd: Warszawa

Ostrzeżenie: (10%)
X----


mowiles viking ale zrobilem tak jak robie zawsze - i znow prawie wszystko dziala. Problem mam teraz ze textarea zamiast pure text daje znaczniki czy to nowej linii czy inne, jak sie tego pozbyc? nl2br() jakos nie dziala

mam tak

  1. <?php
  2.  
  3. ini_set("display_errors", 1);
  4.  
  5. if ($_SERVER['REQUEST_METHOD'] == 'POST')
  6. {
  7. $action = isset($_POST['action']) ? $_POST['action'] : '';
  8. if ($action == "update")
  9. {
  10. $newdatein = $_POST['datein'];
  11. $newcity = $_POST['city'];
  12.  
  13. $dateins = array();
  14. $dateouts = array();
  15. $titles = array();
  16. $programs = array();
  17. $citys = array();
  18. $streets = array();
  19. $places = array();
  20. $seats = array();
  21. $userss = array();
  22.  
  23. $database = './../db/events.csv';
  24. $items = file($database);
  25. $count = 0;
  26. $kodindex = -1;
  27. foreach($items as $line)
  28. {
  29. list($datein, $dateout, $title, $program, $city, $street, $place, $seat, $users) = explode('|', trim($line));
  30. $dateins[$count] = $datein;
  31. $dateouts[$count] = $dateout;
  32. $titles[$count] = $title;
  33. $programs[$count] = $program;
  34. $citys[$count] = $city;
  35. $streets[$count] = $street;
  36. $places[$count] = $place;
  37. $seats[$count] = $seat;
  38. $userss[$count] = $users;
  39.  
  40. if ($newdatein == $datein && $newcity == $city)
  41. {
  42. $kodindex = $count;
  43. }
  44. $count++;
  45. }
  46. $file = fopen($database, 'w');
  47. for ($i = 0; $i < $count; $i++)
  48. {
  49. if ($i == $kodindex)
  50. {
  51. $dateins[$i] = $_POST['datein'];
  52. $dateouts[$i] = $_POST['dateout'];
  53. $titles[$i] = $_POST['title'];
  54. $programs[$i] = nl2br($_POST['program']);
  55. $citys[$i] = $_POST['city'];
  56. $streets[$i] = $_POST['street'];
  57. $places[$i] = $_POST['place'];
  58. $seats[$i] = $_POST['seat'];
  59. $userss[$i] = $_POST['users'];
  60. }
  61. fwrite($file, "".$dateins[$i]."|".$dateouts[$i]."|".$titles[$i]."|".$programs[$i]."|".$citys[$i]."|".$streets[$i]."|".$places[$i]."|".$seats[$i]."|".$userss[$i]."\r\n");
  62. }
  63. fclose($file);
  64. }
  65. header('Location: ./../admin/admin.php');
  66. }
  67. ?>


1.) Jak nie rusze textarea i nadpisze plik, jest OK
2.) jak rusze textarea i dam nie daj boze enter, wywala mi normalnie w pliku csv entery zamiast znacznikow html + dodaje <br />, ktore pozniej widac w edycji jako text

#EDIT

ok rozwiazalem:

tam w formularzu dalem
  1. str_replace("<br/>", "\r\n", $program);

a tu odwrotnie:
  1. str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"), "<br/>", $_POST['program']);


i szafa gra

Ten post edytował shpaque 14.12.2017, 13:09:26
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: 15.10.2025 - 13:53