gpt4 book ai didi

PHP & MySQL - 不插入数据库

转载 作者:行者123 更新时间:2023-11-29 04:35:09 25 4
gpt4 key购买 nike

我的代码有问题。插件不工作。代码如下。

HTML:

<form action="staff.php" method="post" class="center" enctype="multipart/form-data" autocomplete="off">
<input type="hidden" name="size" value="1000000">
<input type="text" placeholder="headline of the news" name="title">
<input type="file" accept="image/*" name="image">
<select name="side" value="side">
<option>Left</option>
<option>Header</option>
<option>Main</option>
<option>Ending</option>
</select>
<textarea name="desc" id="description" cols="30" rows="10" placeholder="full news" name="desc"></textarea>
<input type="submit" name="go" value="Post">
</form>

PHP:

<?php
$db = mysqli_connect("DB SERVER", "DB USER", "DB PASS", "DataBase");
$charset = mysqli_set_charset($db,"utf8");
$msg = "";
if (isset($_POST['go'])) {
$target = "images/".basename($_FILES['image']['name']);
$title = $_POST['title'];
$image = $_FILES['image']['name'];
$side = $_POST['side'];
$desc = $_POST['desc'];
$sql = "INSERT INTO contents (title, image, side, description)
VALUES ('$title', '$image', '$side', '$desc')";
$result = mysqli_query($db, $sql);
if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
$msg = "<p class='success'>Image uploaded successfully</p>";
} else {
$msg = "<p class='error'>There was a problem uploading the image</p>";
}
}
?>

一切正常,除了插入数据库

最佳答案

像这样在查询中添加连接

$sql = "INSERT INTO contents (title, image, side, description) 
VALUES ('".$title."', '".$image."', '".$side."', '".$desc."')";

关于PHP & MySQL - 不插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44923560/

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