Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: int automatycznie się nadpisuje
Forum PHP.pl > Forum > Bazy danych > MySQL
hax0r
Witam tworze sobie system newsów we flashu wysyłam dane z flasha i po przez php łącze się z bazą smile.gif Wszystko działa poprawnie newsy są wyświetlane są zapisywane w bazie ... Problem polega na tym ,że gdy wyświetlam te newsy to za kazdym razem jak je wyswietle tworzy sie pusty wpsi w bazie danych jest podane tylko id nadane przez pole int(11) z auto_increment pozostałe pola to varchar(255) sa puste (Tak samo z siebie sie to nie dzieje tongue.gif)

kod PHP:
  1. <?
  2.  
  3. /* MySQL details */
  4. $dbHost = "sql.baza.pl";
  5. $dbUser = "user";
  6. $dbPass = "pass";
  7. $dbName = "baza";
  8. $table = "downloadLog";
  9.  
  10. /* Attempt connection to MySQL server */
  11. $link = @mysql_connect($dbHost, $dbUser, $dbPass);
  12.  
  13. /* If connection wasn't successful... */
  14. if (!$link) {
  15.  
  16. /* Return error information to Flash and quit! */
  17. print "&news=" . urlencode("<b>Error:</b> Could not conenct to database") . "&";
  18. }
  19.  
  20. /* Attempt to select our database */
  21. /* If not able to select... */
  22. if (!@mysql_select_db($dbName)) {
  23.  
  24. /* Return error information to Flash and quit! */
  25. print "&news=" . urlencode("<b>Error:</b> Could not find $dbName database") . "&";
  26. }
  27.  
  28. /* Fetch current time from server */
  29. $currentTime = time();
  30.  
  31. /* Build SQL query to insert our information into table */
  32. $query = "INSERT INTO $table (tresc, nadawca, entryDate) ";
  33. $query .= "VALUES('$tresc', '$nadawca', $currentTime)";
  34.  
  35. /* Execute query */
  36. $result = mysql_query($query);
  37.  
  38. /* If there was an error executing query... */
  39. if (!$result) {
  40.  
  41. /* Return error information to Flash and quit! */
  42. print "&news=" . urlencode("Error: Could not insert record into download log") . "&";
  43. }
  44.  
  45. /* Build SQL query to fetch all entries from the table */
  46. $query = "SELECT * FROM $table ORDER BY entryDate DESC";
  47.  
  48. /* Execute query */
  49. $result = mysql_query($query);
  50.  
  51. /* If there was a problem with the query... */
  52. if (!$result || @mysql_num_rows($result) < 1) {
  53.  
  54. /* Return error information to Flash and quit! */
  55. print "&news=" . urlencode("No entries in table $table") . "&";
  56. }
  57.  
  58. /* Reset variable to hold output */
  59. $news = "";
  60.  
  61. /* For each table entry returned... */
  62. while($row = mysql_fetch_array($result)) {
  63.  
  64. /* Create human readable date from timestamp */
  65. $entryDate = strftime("%A %d/%m/%y", $row['entryDate']);
  66.  
  67. /* Add details to output variable */
  68. $news .= "<p class='style1'><b>Data:</b> " . $entryDate . "<br></p>";
  69. $news .= "<p class='style2'><b>Nadawca:</b> " . $row['nadawca'] . "<br></p>";
  70. $news .= "<p class='style3'><b>Tresc:</b> " . $row['tresc'] . "<br></p>";
  71.  }
  72.  
  73. /* Output data in required format */
  74. print "&news=" . urlencode($news) . "&";
  75.  
  76.  
  77. /* Close link to MySQL */
  78. mysql_close($link);
  79.  
  80. ?>


Mam nadzieje ,że mi pomożecie ...
Pozdrawiam
nospor
No ale czemu sie dziwisz? Przecież bez warunkowo uruchamiasz ten kod:
  1. <?php
  2. $query = "INSERT INTO $table (tresc, nadawca, entryDate) ";
  3. $query .= "VALUES('$tresc', '$nadawca', $currentTime)";
  4.  
  5. /* Execute query */
  6. $result = mysql_query($query);
  7. ?>

który to właśnie wkłada pustego newsa do bazy. Daj warunek by wkładał tylko wtedy gdy ma wkładać i będzie git smile.gif
hax0r
Rozumiem i dziękuje za pomoc nie mam ppojecia jak to rozwiazac tongue.gif umiem pisac warunki ale tu nie wiem jak sie do tego zabra wiec poprostu zrobie 2 pliki php writ i read i w sumie w ten sposob będzie git prawda tongue.gif

Dzięki i pozdrawiam smile.gif
kwiateusz
w ifie sprawdzasz czy $tresc', '$nadawca', $currentTime nie są puste i wtedy dopiero wykonujesz...
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.