Php mysql发布服务器请求\u方法中缺少的数据

Php mysql发布服务器请求\u方法中缺少的数据,php,mysql,post,Php,Mysql,Post,我有以下代码,每当我尝试插入数据时,$content没有被插入,问题可能在哪里?我使用功能测试输入解决安全相关问题 <?php // define variables and set to empty values $title = $content = $path = $file_type =""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $title = test_input($_POST["title"]); $content

我有以下代码,每当我尝试插入数据时,
$content
没有被插入,问题可能在哪里?我使用功能测试输入解决安全相关问题

<?php
// define variables and set to empty values
$title = $content = $path = $file_type ="";

if ($_SERVER["REQUEST_METHOD"] == "POST")
{
  $title = test_input($_POST["title"]);
  $content = test_input($_POST["content"]);
  $path = test_input($_POST["path"]);
  $file_type = test_input($_POST["file_type"]);

}

function test_input($data)
{
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

$con=mysqli_connect("localhost","---","---","---");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }


$sql="INSERT INTO articles (ArtID,Title,Content,Image_VideoLink_Path,file_type)
VALUES
('','$title','$content','$path',' $file_type')";

if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }
echo "<h2 >Article Published</h2>";
echo"<a href='../mag/index.php'> View it Now </a>";

mysqli_close($con);
?>
尝试此查询:

$sql=“插入到文章中” (标题、内容、图像\视频链接\路径、文件\类型)值 (“$title”、“$content”、“$path”、“$file_type”)


未插入$content,因为您正在提供文章ID。我确信文章ID将显示在您的主键中,并且将自动递增。所以,您不需要在sql查询(语句)中提到文章id。

我们可以看看您的表单吗?或者发布数据的方法?在运行
mysqli\u query($con,$sql)
之前,你能运行
echo$sql
并在你的问题中发布输出吗这里是我从echo$sql插入文章(标题、内容、图像链接路径、文件类型)值('benb'、''、'rr.jpg'、'Image')中得到的内容。Jamie Taylor我现在已经包括了这个表单,你可以检查它,那里的一切似乎都井然有序,非常奇怪,我尝试过更改,但当我回显$sql时,我得到了这样一个结果:插入到文章(标题、内容、图像链接路径、文件类型)值('benb'、''rr.jpg'、'Image')为什么回显$sql?您需要运行查询才能插入到数据库中。如果$sql在键入时为您提供值,则$sql是正确的。您只需要运行查询。您可以这样运行查询:if(!mysqli_query($con,$sql)){die('Error:'.mysqli_Error($con));}
<form  method="POST" action="artPro.php">
  <fieldset>
    <legend>Create New Article</legend>
    <br/>
    Article Title:
    <input type="text" placeholder="enter title here" class="span3" name="title" required>

           Image/Video Path :

           <input type="text" placeholder="enter image name e.g k.jpg or k.mp4 for video" name="path" class="span3" required/>

          File Type :
          <input type="text" name="file_type" class="span3" required placeholder="e.g: image or video"/>

  <br/>

            <label>Article Content:</label>

           <textarea name="content" rows="20"  class="jqte-test span12" required   id="txtmsg"></textarea>


<br><button type="submit" class="btn btn-primary btn-large pull-right">Publish</button>
  </fieldset>
</form>