Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP] Formularz wysła sie kilka razy
boro11
post 22.09.2011, 14:22:34
Post #1





Grupa: Zarejestrowani
Postów: 283
Pomógł: 11
Dołączył: 9.07.2010
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Witam!
Mam problem z jednym z formularzy. Problem tkwi w tym że wysyła sie ona po kilka razy - do bazy danych dodaje się więcej rekordów niż powinno. Czasami po 2-3 a nie 1 jak powinno być.

Kod:

  1. <?php
  2. require("connection.php");
  3. connection();
  4.  
  5. $username = ($_POST['username']);
  6. $status = $_POST['status'];
  7. $url = $_POST['url'];
  8. $data = $_POST['data'];
  9.  
  10.  
  11.  
  12. $zapytanie = "INSERT INTO `mproof` VALUES(' ','$username','$status','$url','$data')";
  13. mysql_query($zapytanie);
  14.  
  15.  
  16.  
  17. $dir = "./proof/"; //Change this to the correct dir RELATIVE TO WHERE THIS SCRIPT IS, or /full/path/
  18.  
  19. //MIME types to allow, Gif, jpeg, zip ::Edit this to your liking
  20. $types = array("image/png","image/x-png","image/gif","image/jpeg","image/pjpeg","image/jpg","image/bmp");
  21.  
  22. // Nothing to edit below here.
  23.  
  24. //Function to do a directory listing
  25. function CPGscandir($dirstr) {
  26. echo "<pre>\n";
  27. passthru("ls -l -F $dirstr 2>&1 ");
  28. echo "</pre>\n";
  29. }
  30.  
  31. //Check to determine if the submit button has been pressed
  32. if(isset($_POST['submit'])){
  33.  
  34. //Shorten Variables
  35. $rand=rand(1,99);
  36. $tmp_name = $_FILES['upload']['tmp_name'];
  37. $new_name = $rand.$_FILES['upload']['name'];
  38. $path = $_POST['subdir'];
  39. $fullpath = "$dir$path/";
  40. $fullpath = str_replace("..", "", str_replace("\.", "", str_replace("//", "/", $fullpath)));
  41. $clean_name = ereg_replace("[^a-z0-9._]", "", str_replace(" ", "_", str_replace("%20", "_", strtolower($new_name) ) ) );
  42.  
  43. // lets see if we are uploading a file or doing a dir listing
  44. if(isset($_POST['Dir'])){
  45. echo "Directory listing for $fullpath\n";
  46. scandir("$fullpath");
  47. }else{
  48.  
  49.  
  50. //Check MIME Type
  51. if ((in_array($_FILES['upload']['type'], $types)) and (!file_exists($fullpath.$clean_name))){
  52.  
  53. // create a sub-directory if required
  54. if (!is_dir($fullpath)){
  55. mkdir("$fullpath", 0755);
  56. }
  57. //Move file from tmp dir to new location
  58. move_uploaded_file($tmp_name,$fullpath . $clean_name);
  59.  
  60. echo "<br />Your proof is uploaded correctly!";
  61.  
  62. }else{
  63.  
  64. //Print Error Message
  65. echo "<small>File <strong><em>{$_FILES['upload']['name']}</em></strong> Was Not Uploaded - bad file type or file already exists</small><br />";
  66. //Debug
  67. $name = $_FILES['upload']['name'];
  68. $type = $_FILES['upload']['type'];
  69. $size = $_FILES['upload']['size'];
  70. $tmp = $_FILES['upload']['name'];
  71.  
  72. echo "Name: $name<br />Type: $type<br />Size: $size<br />Tmp: $tmp";
  73.  
  74. }
  75.  
  76. }
  77. } else {
  78. echo '';
  79. } ?>
  80. <br />
  81. <div id="TOS">
  82. <form action="" method="post" enctype="multipart/form-data">
  83.  
  84. Please upload your payment proof it will help us to grow faster and make our website even more reliable.<br /><br /><br />
  85.  
  86. <input type="hidden" name="username" value="<?=$_SESSION['login']?>"/>
  87. <input type="hidden" name="status" value="Approved"/>
  88. <input type="hidden" name="url" value="Test"/>
  89. <input type="hidden" size="40" value="<? $dzien0=date("d"); $miesiac0=date("m"); $rok0=date("Y"); echo "$rok0-$miesiac0-$dzien0"; ?>" name="data">
  90. <input type="file" name="upload" /> <br /><br />
  91. <input type="submit" name="submit" value="Upload" />
  92.  
  93. </form>
  94. </div>



Kolejnym problemem jest to że nie przesyła się informacja z pola username, zawsze używałem tej samej metody tzn.
  1. <?=$_SESSION['login']?>
i wszystko się pięknie przesyłało. Czy może mieć na to wpływ rodzaj formularza ?

Ten post edytował boro11 22.09.2011, 14:23:03
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 24.07.2025 - 19:56