그래서 테이블에 입력 된 데이터를 보내는 간단한 양식을 만들었습니다. 내가 가진 문제는 '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>
로컬 호스트 서버의 POST 제한은 얼마입니까? – JBithell
side note : 매개 변수가있는 쿼리를 사용해야합니다. 현재 상태에서는 코드가 SQL 인젝션에 취약합니다. 누군가를 상상해보십시오. DROP TABLE posts; --' –
'post_image' 열에 대한 열 유형은 무엇입니까? 여기서 무엇을하고 싶습니까? "이름"또는 이미지 자체를 사용 하시겠습니까? –