2016-10-20 3 views
-1

그래서 테이블에 입력 된 데이터를 보내는 간단한 양식을 만들었습니다. 내가 가진 문제는 'content'필드의 문자 수가 특정 숫자를 초과 할 때마다 제출을 누르고 모든 필드가 비어 있고 데이터가 테이블에 전송되지 않습니다. 일단 '제출 된 게시물은 성공적으로 게시되었습니다.'라는 메시지를 받아야하지만, 위와 같은 이유로 인해 발생하지 않으며 이유가 없습니다.양식 데이터가 올바르게 제출되지 않음

그런 다음 localhost로 이동하여 필드를 편집해야합니다. 당신이 shouldn로

<?php 
include("includes/connect.php"); 

if(isset($_POST['submit'])) { 

    $post_title = $_POST['title']; 
    $post_date = date('Y-m-d'); 
    $post_author = $_POST['author']; 
    $post_keywords = $_POST['keywords']; 
    $post_content = $_POST['content']; 
    $post_image = $_FILES['image']['name']; 
    $image_tmp = $_FILES['image']['tmp_name']; 


    if($post_title == '' or $post_keywords == '' or $post_content == '' 
    or $post_author == '') { 

     echo "<script>alert('Please fill the empty fields!')</script>"; 

     exit(); 
    } 
    else { 

     move_uploaded_file($image_tmp, "../images/$post_image"); 

     $insert_query = "INSERT INTO `posts` 
     (post_title, post_date, post_author, post_image, 
     post_keywords, post_content) 
     values ('$post_title', '$post_date', '$post_author', '$post_image', 
     '$post_keywords', '$post_content')"; 

     if(mysqli_query($connect, $insert_query)) { 

      echo "<center><h1>Post Published Successfully!</h1></center>"; 
     } else echo "MySQL Error description: " . mysqli_error($connect); 
    } 

} 
?> 

프로덕션 환경에서이를 사용하지 마십시오 : -이 같은 자신에게 문제의 더 나은 아이디어를주고 처리하는 일부 MySQL의 오류를 포함

<?php 
include("includes/connect.php"); 

if(isset($_POST['submit'])) { 

    $post_title = $_POST['title']; 
    $post_date = date('Y-m-d'); 
    $post_author = $_POST['author']; 
    $post_keywords = $_POST['keywords']; 
    $post_content = $_POST['content']; 
    $post_image = $_FILES['image']['name']; 
    $image_tmp = $_FILES['image']['tmp_name']; 


    if($post_title == '' or $post_keywords == '' or $post_content == '' 
    or $post_author == '') { 

     echo "<script>alert('Please fill the empty fields!')</script>"; 

     exit(); 
    } 
    else { 

     move_uploaded_file($image_tmp, "../images/$post_image"); 

     $insert_query = "INSERT INTO `posts` 
     (post_title, post_date, post_author, post_image, 
     post_keywords, post_content) 
     values ('$post_title', '$post_date', '$post_author', '$post_image', 
     '$post_keywords', '$post_content')"; 

     if(mysqli_query($connect, $insert_query)) { 

      echo "<center><h1>Post Published Successfully!</h1></center>"; 
     } 
    } 

} 
?> 

<body> 

    <form method = "post" action = "insert_post.php" enctype = "multipart/form-data"> 

     <table width = "600" align = "center"> 
      <tr> 
       <td align="center" colspan = "6"><h1 style = "font-family: 'Fjalla One'; color: #575757;">Insert new post here</h1></td> 
      </tr> 

      <tr><!--TITLE--> 
       <td align = "right" size = "30px" style = "font-family: 'Fjalla One'; color: #575757; font-size: 20px;">Post Title:</td> 
       <td><input type = "text" name = "title"></td> 
      </tr> 

      <tr><!--AUTHOR--> 
       <td align = "right" size = "30px" style = "font-family: 'Fjalla One'; color: #575757; font-size: 20px;">Post Author:</td> 
       <td><input type = "text" name = "author"></td> 
      </tr> 

      <tr><!--KEYWORDS--> 
       <td align = "right" size = "30px" style = "font-family: 'Fjalla One'; color: #575757; font-size: 20px;">Post Keywords:</td> 
       <td><input type = "text" name = "keywords"></td> 
      </tr> 

      <tr><!--IMAGE--> 
       <td align = "right" style = "font-family: 'Fjalla One'; color: #575757; font-size: 20px;">Post Image:</td> 
       <td><input type = "file" name = "image"></td> 
      </tr> 

      <tr><!--CONTENT--> 
       <td align = "right" style = "font-family: 'Fjalla One'; color: #575757; font-size: 20px;">Post Content</td> 
       <td><textarea name = "content" cols = "40" rows = "20"></textarea></td> 
      </tr> 

      <tr> 
       <td align = "center" colspan = "6"><input type = "submit" name = "submit" value = "Publish" ></td> 
      </tr> 

    </form> 
+0

로컬 호스트 서버의 POST 제한은 얼마입니까? – JBithell

+2

side note : 매개 변수가있는 쿼리를 사용해야합니다. 현재 상태에서는 코드가 SQL 인젝션에 취약합니다. 누군가를 상상해보십시오. DROP TABLE posts; --' –

+0

'post_image' 열에 대한 열 유형은 무엇입니까? 여기서 무엇을하고 싶습니까? "이름"또는 이미지 자체를 사용 하시겠습니까? –

답변

1

시도 : 여기 내 코드입니다 최종 사용자에게 기술적 인 오류 메시지를 표시하지 마십시오. 특히 원시 입력을 피할 수 없기 때문에 SQL 주입이 자주 발생합니다.


편집 :

연산 붙여 오류 메시지가 문자열에 ' 문자가 MySQL이 에러의 원인이 제출 보여주는 - 솔루션은 mysqli_real_escape_string($connect, $variable);를 통해 제출 된 모든 변수를 전달하는 것입니다.

+0

고마워요. 나는 이것을 지금 시도 할 것이다 –

+0

MySQL 오류 설명 : SQL 구문에 오류가 있습니다. MariaDB 서버 버전에 해당하는 설명서를 확인하여 올바른 구문을 사용하여 가까운 곳에서 더 많은 뉴스를보고 다시 팬을 흥분하게하십시오. 최근 5시에 나와있는 소셜 네트워크의 게시물에서 –

+0

그게 내가 지금 받고있는 오류예요 –

관련 문제