Hej Wszystkim.
Wiem, ze temat ze znakami jest już wałkowany od dawna.
Ale mam następujący problem otóż: wszędzie mam ustawiony UTF-8, w edytorze UTF-8 witout BOM.
W bazie UTF8_polish_ci.

Mam 2 formularze: jeden z tylko z możliwością dodania danych tekstowych do bazy,
na nim wrzuca mi polskie znaki do tabeli w bazie bez problemu.

2 w którym mam formularz + dodatkowo miejsce na upload pliku.
Ale: Załączenie pliku nie jest wymagane aby dodało dane z formularza do bazy.
Właśnie na tym formularzu i skrypcie pojawia się problem: brak polskich znaków przy insercie danych z formularzy do bazy.
Krzaki wrzuca !

Dla funkcjonalności dobrze mieć za jednym zamachem dodanie formularza i pliku do bazy w jednym miejscu.
Oczywiście jeśli rozdzielę formularz i upload pliku jest wszystko ok.

Jak sobie z tym poradzić questionmark.gif


Kod formularza:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <script type="text/javascript" src="js/calendar.js"></script>
  6. <script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
  7. <script src="js/jquery-ui-1.8.19.custom.min.js" type="text/javascript"></script>
  8. <link rel="stylesheet" href="css/jquery-ui-1.8.19.custom.css"
  9. type="text/css" />
  10. <style>
  11. body {
  12. font-size: 12px;
  13. font-family:Arial;
  14.  
  15. }
  16. </style>
  17.  
  18. <title>Dodaj Dokumenty</title>
  19.  
  20. </head>
  21.  
  22.  
  23. <?php
  24. ini_set('default_charset', 'UTF-8');
  25. $file = file_get_contents('./header.inc.php', FILE_USE_INCLUDE_PATH);
  26. echo $file;
  27. ?>
  28. <body>
  29.  
  30. <h2>
  31. Dodaj dokument do dzialki (nr id
  32. <?php echo $_GET['iddzialki'] ?>
  33. )
  34. </h2>
  35. <form action="add_file_dok.php" method="post" enctype="multipart/form-data" >
  36. <input type="hidden" value="<?php echo $_GET['iddzialki'] ?>" id="iddzialki" name="iddzialki"/>
  37.  
  38. <table border="0">
  39. <tr>
  40. <td></td>
  41. <td><input type="hidden" name="id" maxlength="30" size="30" id="id"/></td>
  42. </tr>
  43. <tr>
  44. <td>rodz_dok</td>
  45. <td><SELECT name="rodz_dok" id="rodz_dok" >
  46. <?php
  47. ini_set('default_charset', 'UTF-8');
  48. include ('conf.php');
  49.  
  50. $link = mysql_connect( $DB_HOST, $DB_USER, $DB_PASS) or die ("Nie można się połączyć");
  51. mysql_select_db ($DB_DATABASE) or die ("Nie mozna wybrać bazy danych");
  52.  
  53. $zapytanie = mysql_query("select * from rodzaj_dokumentu order by rodzaj");
  54. while ($rodzaj = mysql_fetch_array($zapytanie))
  55. {
  56. echo '<OPTION value="'.$rodzaj['rodzaj'].'">'.$rodzaj['rodzaj'].'</OPTION>';
  57. }
  58. ?>
  59. </SELECT></td>
  60. </tr>
  61. <tr>
  62. <td>nr_dokumentu</td>
  63. <td><input type="text" name="nr_dokumentu" maxlength="50" size="30"
  64. id="nr_dokumentu"></td></input>
  65. </tr>
  66. <tr>
  67. <td>SKAN_dokumentu</td>
  68.  
  69. <td><input type="file" name="uploaded_file"><br></td>
  70.  
  71.  
  72. </tr>
  73. <tr>
  74. <td>status_negocjacji</td>
  75. <td><input type="text" name="status_negocjacji" maxlength="30" size="30"
  76. id="status_negocjacji">
  77. </td>
  78. </tr>
  79. <tr>
  80. <td>data_podpisania Format RRRR-MM-DD</td>
  81. <td><input type="text" name="data_podpisania" maxlength="30" size="30"
  82. id="data_podpisania">
  83. </td>
  84. </tr>
  85. <tr>
  86. <td>uwagi</td>
  87. <td><TEXTAREA type="text" name="uwagi" rows="4" cols="20"
  88. id="uwagi"></TEXTAREA></td>
  89. </tr>
  90. <tr>
  91. <td colspan="2"><input type="submit" value="ZAPISZ"></td>
  92. </tr>
  93.  
  94. </table>
  95. </form>
  96.  
  97. <?php
  98. $file = file_get_contents('./footer.inc.php', FILE_USE_INCLUDE_PATH);
  99. echo $file;
  100. ?>


KOD do dodawania do bazy:

  1. <?php
  2. ini_set('default_charset', 'UTF-8');
  3. $file = file_get_contents('./header.inc.php', FILE_USE_INCLUDE_PATH);
  4. echo $file;
  5.  
  6. // Check if a file has been uploaded
  7. if(isset($_FILES['uploaded_file'])) {
  8. // Make sure the file was sent without errors
  9. if($_FILES['uploaded_file']['error'] == 0) {
  10. // Connect to the database
  11. $dbLink = new mysqli('localhost', 'root', 'pass123##', 'baza');
  12. if(mysqli_connect_errno()) {
  13. die("MySQL connection failed: ". mysqli_connect_error());
  14. }
  15.  
  16. // Gather all required data
  17. $name_d = $dbLink->real_escape_string($_FILES['uploaded_file']['name']);
  18. $mime_d = $dbLink->real_escape_string($_FILES['uploaded_file']['type']);
  19. $data_d = $dbLink->real_escape_string(file_get_contents($_FILES ['uploaded_file']['tmp_name']));
  20. $size_d = intval($_FILES['uploaded_file']['size']);
  21.  
  22.  
  23.  
  24. // Create the SQL query
  25. $query = "update dokumenty set name_d='".$name_d."' , mime_d='".$mime_d."', data_d='".$data_d."' , size_d='".$size_d."' WHERE id=".((int)$_GET['id']);
  26. //echo $query;
  27. // Execute the query
  28. $result = $dbLink->query($query);
  29.  
  30. // Check if it was successfull
  31. if($result) {
  32. echo 'Success! Twoj plik został dodany do bazy! :)';
  33. }
  34. else {
  35. echo 'Error! Failed to insert the file'
  36. . "<pre>{$dbLink->error}</pre>";
  37. }
  38. }
  39. else {
  40. echo 'An error accured while the file was being uploaded. '
  41. . 'Error code: '. intval($_FILES['uploaded_file']['error']);
  42. }
  43.  
  44. // Close the mysql connection
  45. $dbLink->close();
  46. }
  47. else {
  48. echo 'Error! A file was not sent!';
  49. }
  50.  
  51. // Echo a link back to the main page
  52. echo '<p>Click <a href="index.html">here</a> to go back</p>';
  53. $file = file_get_contents('./footer.inc.php', FILE_USE_INCLUDE_PATH);
  54. echo $file;
  55. ?>
  56.  
  57.