gpt4 book ai didi

php - 带有 php 的 html 文本形式没有插入到 MySQL 服务器中

转载 作者:行者123 更新时间:2023-11-28 23:51:42 25 4
gpt4 key购买 nike

output + code

我正在编写生成 <textarea> 的代码让用户输入一些东西,但除了“请包含一些内容”之外,它没有给我任何输出,如果框中没有任何内容,这就是它的意思。即使 <textarea> 中有内容,也会出现这种情况甚至不会说“失败后”,如果它无法插入数据库,这就是它的本意。

我想问是否有人可以查看是否有我忽略的内容,或者我的代码是否有问题。

<?php
session_start();
require('connect.php');
if(@$_SESSION["name"]){
//echo "welcome ".$_SESSION['name'];
?>
<html>
<link rel="stylesheet" type="text/css" href="styles.css" />
<head>
<title> Welcome to faecesbook</title>
</head>
<?php include('header.php'); ?>
<form action="post.php" method="POST">
<br / >
<br / >
<br / >
<br / >
<center>
<br/>
<br/>
Type your post here:<br/>(160CharLimit)<br/>
<textarea style="resize: none; width: 800px; height: 100px;" name="con" maxlength="160">
</textarea>
<br />
<input type="submit" name="submit" value="Post" style="width: 800px;" >
</center>
</form>
<body>
</body>
</html>

<?php
$content = @$_POST['con'];
$post_date = date("d-m-y");


if(isset($_POST['submit'])){
if($content){
if($query = mysqli_query($conn, "INSERT INTO post(`postID`, `userID` , `post_date` , `in_reply_to`, `postContent` )
VALUES ('','".$_SESSION["userID"]."','".$post_date."','','".$content."')") )
echo "post successful";
}else{
echo "post fail";
}

}else{
echo "Please include some content";
}
}

?>

最佳答案

试试这段代码。它应该有效。

<?php
session_start();
require('connect.php');
if(@$_SESSION["name"]){
//echo "welcome ".$_SESSION['name'];
?>
<html>
<link rel="stylesheet" type="text/css" href="styles.css" />
<head>
<title> Welcome to faecesbook</title>
</head>
<?php include('header.php'); ?>
<form action="post.php" method="POST">
<br / >
<br / >
<br / >
<br / >
<center>
<br/>
<br/>
Type your post here:<br/>(160CharLimit)<br/>
<textarea style="resize: none; width: 800px; height: 100px;" name="con" maxlength="160">
</textarea>
<br />
<input type="submit" name="submit" value="Post" style="width: 800px;" >
</center>
</form>
<body>
</body>
</html>

<?php
$post_date = date("d-m-y");
if(isset($_POST['submit'])){
if(isset($_POST['con']) && $_POST['con'] != ''){
$content = @$_POST['con'];
if($query = mysqli_query($conn, "INSERT INTO post(`postID`, `userID` , `post_date` , `in_reply_to`, `postContent` )
VALUES ('','".$_SESSION["userID"]."','".$post_date."','','".$content."')") )
echo "post successful";
}else{
echo "post fail";
}

}else{
echo "Please include some content";
}
}

?>

关于php - 带有 php 的 html 文本形式没有插入到 MySQL 服务器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32477447/

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