Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][HTML][PHP] Nie chce dodać rekordu do bazy
Forum PHP.pl > Forum > Przedszkole
Spawacz123
Witam serdecznie napisałem z kolegą skrypt php który dodaje prace do portfolio niestety po dodaniu np. znacznika <img src="" /> do pola textarea rekord nie dodaje się do bazy nie mam już zielonego pojęcia co może być źle dodam również że bez znaczników rekord wysyłą się do bazy

  1. <?php
  2. $db = mysql_connect('', '', '');
  3. mysql_select_db('', $db);
  4.  
  5. if (isset($_POST['submitted'])) {
  6. $query = sprintf('INSERT INTO galery (TITLE, CATEGORY, DESCRIPTION) ' .
  7. 'VALUES ("%s", "%s", "%s")', $_POST['title'], $_POST['category'],
  8. $_POST['description']);
  9. mysql_query($query, $db);
  10. $insert_id = mysql_insert_id($db);
  11.  
  12. for ($i=0; $i<$_POST['count']; $i++) {
  13. $key = explode('.', $_FILES['files']['name'][$i]);
  14. $key = array_pop($key);
  15. if (move_uploaded_file($_FILES['files']['tmp_name'][$i], '../images/' . $insert_id . '_' . $i . '.' . $key)) {
  16. $query = sprintf('INSERT INTO images (GALERY_ID, PATH) VALUES (%d, "%s")',
  17. $insert_id, 'images/' . $insert_id . '_' . $i . '.' . $key);
  18. mysql_query($query, $db);
  19. }
  20. }
  21.  
  22. $key = explode('.', $_FILES['cat_img']['name']);
  23. $key = array_pop($key);
  24. if (move_uploaded_file($_FILES['cat_img']['tmp_name'], '../images/' . $insert_id . '_catImg.' . $key)) {
  25. $query = sprintf('INSERT INTO images (GALERY_ID, PATH, CAT_IMG) VALUES ' .
  26. '(%d, "%s", %d)', $insert_id, '../images/' . $insert_id . '_catImg.' . $key, 1);
  27. mysql_query($query, $db);
  28. }
  29.  
  30. $key = explode('.', $_FILES['min_img']['name']);
  31. $key = array_pop($key);
  32. if (move_uploaded_file($_FILES['min_img']['tmp_name'], '../images/' . $insert_id . '_minImg.' . $key)) {
  33. $query = sprintf('INSERT INTO images (GALERY_ID, PATH, MIN_IMG) VALUES ' .
  34. '(%d, "%s", %d)', $insert_id, '../images/' . $insert_id . '_minImg.' . $key, 1);
  35. mysql_query($query, $db);
  36. }
  37.  
  38. echo '<p style="width:450px; padding:20px; background-color: #333333; text-align: center; color: lime; font-weight: bold;">PLIKI POMYŚLNIE WYSŁANO NA SERWER<br>DANE POPRAWNIE ZAPISANO W BAZIE</p>';
  39. }
  40. ?>


  1. <form name="form1" method="POST" enctype="multipart/form-data">
  2. <tr>
  3. <td><label for="title">Tytuł:</label></td>
  4. <td><input type="text" class="inpu" name="title" id="title" /></td>
  5.  
  6. </tr> <tr>
  7. <td><label for="category">Kategoria:</label></td>
  8. <td><input type="text" class="inpu" name="category" id="category" /></td>
  9. </tr> <tr>
  10. <td><label for="description">Opis:</label></td>
  11. <td><textarea name="description" id="elm1" name="elm1" rows="20" cols="220" style="width: 80%;"></textarea></td>
  12. </tr> <tr>
  13. </tr><tr><td><br></td></tr>
  14. <td>Obrazek kategorii: </td>
  15. <td><input type="file" name="cat_img" value="" /> (168px na 173px)</td>
  16. </tr><tr><td><br></td></tr>
  17. </tr> <tr>
  18. <td>Obrazek miniaturki:</td>
  19. <td><input type="file" name="min_img" value="" /> (168px na 173px)</td>
  20. </tr><tr><td><br></td></tr>
  21. </tr>
  22. <tbody style="margin-left:-100px;" id="elements">
  23. <tr id="new_files">
  24. <td><label>Obrazek główny: </label></td>
  25. <td><input type="file" name="files[]" /> (734px na 413px)</td>
  26. </tr>
  27. </tbody>
  28. </table>
  29. <br><br>
  30. <input type="hidden" id="" name="count" value="1" />
  31. <input type="submit" name="submitted" value="Wyślij pracę na serwer" />
  32. </form>
mmmmmmm
W 9 linii dodaj :
or die(mysql_error());
buliq
Po pierwsze, twój skrypt ma tyle luk co ser szwajcarski. Dlaczego dane z post bezpośrednio wstawiasz do bazy?
Podczas zapisywania desc do bazy użyj htmlspecialchars a podczas wyświetlania użyj htmlspecialchars_decode
Spawnm
mysql_real_escape_string
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.