gpt4 book ai didi

php - mysql 发布来自 SERVER REQUEST_METHOD 的丢失数据

转载 作者:行者123 更新时间:2023-11-30 00:33:34 26 4
gpt4 key购买 nike

我有以下代码,每当我尝试插入数据时,$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);
?>

这是表单的代码:

<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>

最佳答案

尝试这个查询:

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

$content 未被插入,因为您提供了文章 ID。我确信文章 ID 将是您的主键,并且会自动递增。因此,您不需要在 sql 查询(语句)中提及文章 id。

关于php - mysql 发布来自 SERVER REQUEST_METHOD 的丢失数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22350019/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com