gpt4 book ai didi

PHP - 将数据插入数据库

转载 作者:行者123 更新时间:2023-11-29 04:38:44 27 4
gpt4 key购买 nike

<分区>

我想问一下这个代码..我从 PHP 和 MYSQL 开始,我不明白为什么它不会 INSERT INTO db 即使我连接了..

基本上 php 代码在 “SUBMIT” 后不起作用,我没有收到消息,什么都没有..感谢您的帮助

add_post.php:

<form>
<div class="form-group">
<label for="post_title">title</label>
<input type="text" class="form-control" id="post_title" name="title"/>
</div>
<div class="form-group">
<label for="post_video">video</label>
<input type="text" class="form-control" id="post_video" name="video"/>
</div>
<div class="form-group">
<label for="post_content">content</label>
<textarea rows="10" id="post_content" class="form-control" name="content"></textarea>
</div>
<div class="form-group">
<label for="file_input">file input</label>
<input type="file" id="file_input" name="image">
<p class="help-block">Max upload file is 5MB.</p>
</div>
<button class="btn btn-default" name="submit">Submit</button>
</form>

<?php
include('connect.php');

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

$post_title = $_POST['title'];
$post_date = date('d-m-y');
$post_video = $_POST['video'];
$post_content = $_POST['content'];
$post_image = $FILES['image'];

if(empty($post_title) || empty($post_content)) {
echo "<script>alert('title or content is empty')</script>";
}
else {
move_uploaded_file($post_image,"image/uploads/$post_image");

$insert_query = "INSERT INTO post (title, image, content, video) VALUES (
'$post_title',
'$post_image',
'$post_content',
'$post_video')";

if(mysqli_query($db, $insert_query)) {
echo "<center><h1>post published successfuly</h1></center>";
}
}

}
?>

connect.php(针对 C9.com):

<?php
// A simple PHP script demonstrating how to connect to MySQL.
// Press the 'Run' button on the top to start the web server,
// then click the URL that is emitted to the Output tab of the console.

$servername = getenv('IP');
$username = getenv('C9_USER');
$password = "";
$database = "portfolio";
$dbport = 3306;

// Create connection
$db = new mysqli($servername, $username, $password, $database, $dbport);

// Check connection
if ($db->connect_error) {
die("Connection failed: " . $db->connect_error);
}
?>

数据库截图:

enter image description here enter image description here

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