Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么每次刷新时php fom提交都会不断提交?_Javascript_Php_Jquery_Html_Forms - Fatal编程技术网

Javascript 为什么每次刷新时php fom提交都会不断提交?

Javascript 为什么每次刷新时php fom提交都会不断提交?,javascript,php,jquery,html,forms,Javascript,Php,Jquery,Html,Forms,因此,我提交表单,每次单击ctrl-r,它都会刷新页面,而不会提醒我,它会重新提交表单。每次我单击浏览器上的“重新加载”按钮时,它都会要求我重新加载,但我已经提交了表单,所以现在我每次都会收到一个新的提交,并在我的sqlDB中创建一个新项目。我刷新,我不知道我要做什么,以自动刷新页面,它不会保存表单重新提交,就像一个新的页面 //end else所在的位置是我尝试添加标题(位置:)的位置,但出现错误。我把错误更多地贴到了问题的底部 footer.php <?php if(isset($_P

因此,我提交表单,每次单击ctrl-r,它都会刷新页面,而不会提醒我,它会重新提交表单。每次我单击浏览器上的“重新加载”按钮时,它都会要求我重新加载,但我已经提交了表单,所以现在我每次都会收到一个新的提交,并在我的sqlDB中创建一个新项目。我刷新,我不知道我要做什么,以自动刷新页面,它不会保存表单重新提交,就像一个新的页面

//end else所在的位置是我尝试添加标题(位置:)的位置,但出现错误。我把错误更多地贴到了问题的底部

footer.php

<?php
if(isset($_POST['submit-story'])){

    $answer = $_POST['human-story'];

    if (!ctype_digit($answer) == 8) {
      echo "Cannot store event. wrong answer";
      die();      
    } else {
    //Get the uploaded file information
    $name_of_uploaded_file = basename($_FILES['uploaded_file']['name']);
    //get the file extension of the file
    $type_of_uploaded_file =
        substr($name_of_uploaded_file,
        strrpos($name_of_uploaded_file, '.') + 1);

    $size_of_uploaded_file =
    $_FILES["uploaded_file"]["size"]/1024;//size in KBs

    //Settings
    $max_allowed_file_size = 1000000; // size in KB
    $allowed_extensions = array("jpg","jpeg","gif","bmp","mp4", "mov");

    //Validations
    if($size_of_uploaded_file > $max_allowed_file_size )
    {
      $errors = "\n Size of file should be less than $max_allowed_file_size";
    }

    //------ Validate the file extension -----
    $allowed_ext = false;
    for($i=0; $i<sizeof($allowed_extensions); $i++)
    {
      if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
      {
        $allowed_ext = true;
      }
    }

    if(!$allowed_ext)
    {
      $errors = "\n The uploaded file is not supported file type. ".
      "Only the following file types are supported: ".implode(',',$allowed_extensions);
    }

    //copy the temp. uploaded file to uploads folder
      $upload_folder = 'uploads/';
      $to = "example@gmail.com"; // this is your Email address
      $first_name = filter_var($_POST['first_name']. $schoolOfficialShortName, FILTER_SANITIZE_STRING);
      $story = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
      $eventDate = filter_var($_POST['eventDate'],FILTER_SANITIZE_STRING);
      $eventLocation = filter_var($_POST['eventLocation'],FILTER_SANITIZE_STRING);
      $subject = "blah-" . $schoolOfficialShortName . "Event";
      $title = filter_var($_POST['title'], FILTER_SANITIZE_STRING);
      $message = $first_name . " wrote the following:" . "\n\n" . $title ."<br>". $story;
      $headers = "From: $first_name";
      // boundary
      $semi_rand = md5(time());
      $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
      // headers for attachment
      $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
      // multipart boundary
      $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
      $message .= "--{$mime_boundary}\n";
      $content = '';
      $tmp_path = $_FILES["uploaded_file"]["tmp_name"];
        if($tmp_path) {
          $filename = $_FILES["uploaded_file"]["name"];
          $path_of_uploaded_file = $upload_folder . $filename;
          if(!copy($tmp_path, $path_of_uploaded_file))
          {
            $errors = '\n error while copying the uploaded file';
          }
          $file_size = filesize($path_of_uploaded_file);
          $handle = fopen($path_of_uploaded_file, "rb");
          $content = fread($handle, $file_size);
          fclose($handle);
          $content = chunk_split(base64_encode($content));
        }
        // if attachment has successfully encoded
        if ($content) {
        $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"{$filename}\"\n" .
        "Content-Disposition: attachment;\n" . " filename=\"{$filename}\"\n" .
        "Content-Transfer-Encoding: base64\n\n" . $content . "\n\n";
        $message .= "--{$mime_boundary}\n";
        }
        $headers2 = "From:" . $to;
        mail($to, $subject, $message, $headers);
        //send items to S3 bucket
        move_uploaded_file($upload_folder, $filename);

        //store image to s3 bucket
        try {
            $result = $s3->putObject([
              'Bucket' => $config['s3']['bucket'],
              'Key' => "uploads/{$name_of_uploaded_file}",
              'Body' => fopen($path_of_uploaded_file, 'rb'),
              'ACL' => 'public-read'
            ]);

            $results = $result['ObjectURL'];

            if (is_uploaded_file($_FILES['uploaded_file']['tmp_name'])){
                  //inserts in pending table
                  $sql = "INSERT INTO items (photo,title,eventDate,description,name,pLike,pDislike,address) VALUES ( :photo, :title, :eventDate, :description, :name, :pLike, :pDislike, :address)";
                  $stmt = $pdo->prepare($sql); 
                  $stmt->bindParam(':title', $title);
                  $stmt->bindParam(':photo', $results);
                  $stmt->bindParam(':description', $story);
                  $stmt->bindParam(':eventDate', $eventDate);
                  $stmt->bindParam(':address', $eventLocation);
                  $stmt->bindParam(':name', $first_name);
                  $stmt->bindValue(':pLike', 0, PDO::PARAM_INT);
                  $stmt->bindValue(':pDislike', 0, PDO::PARAM_INT);
                  $stmt->execute();       
                }else {
                  die("<h1>There was an error. Please go back and retry.</h1>");        
                } 
                //remove the pending file in uploads folder
                unlink($path_of_uploaded_file);

        } catch(PDOException $e){
            echo 'error in query:  '.$e->getMessage();
        }
      };// end else 
};// end isset final
?>
  • 在处理footer.php中的数据后取消设置$\u POST变量

  • 您的标题已发送问题:这意味着某些文本已被输出。将标题()放在脚本顶部。或者看看ob_start和ob_end_clean()函数

  • 文本输出到浏览器后,不能使用header()。由于头文件包含HTML,因此不能使用header()

    您可以通过以下方式解决此问题:

  • 将if语句移到头文件include上方
  • ob_start()位于脚本顶部,用于缓冲输出

  • 我以前看过那篇文章,但我不明白在我的文章中哪里可能会发生错误?抱歉,如果这是多余的,但我需要有人帮助我了解如何解决我的刷新后问题
    Cannot modify header information - headers already sent by (output started at /Users/mine/Documents/www/website/schools/inc/header.php:67) in /Users/mine/Documents/www/website/schools/inc/footer.php on line 127