gpt4 book ai didi

php - 设置帖子的最小字符长度

转载 作者:行者123 更新时间:2023-12-02 14:28:52 26 4
gpt4 key购买 nike

我得到了用于发布博客标题和正文以及其他一些内容的代码。现在我想使用 strlen 设置标题和正文的最小字符长度,我的代码是

 if(isset($_POST['submit'])) {
$title=$_POST['title'];
$body=$_POST['body'];
$category=$_POST['category'];
$title = mysql_real_escape_string($title);
$body = mysql_real_escape_string($body);
$posted_by = $user;
$bio = $bio;
$id=$_SESSION['id'];
$date = date ('Y-m-d');
$body = htmlentities($body);
if ($title && $body && $category) {
$query = mysql_query("INSERT INTO blogs (id, title, body, posted_by, bio, category_id, posted) VALUES ('$id', '$title', '$body', '$posted_by','$bio', '$category', '$date')");
if($query) {
echo "posted";
}
else {
echo "error";
}
}else {
echo "data missing";
}
}

此代码工作正常,只是想插入标题和正文的最少字符要求。我用 strlen 尝试了一些 if else 语句,但我不是编程专家,所以我遇到了语法错误。

最佳答案

这可能对你有帮助..

 if(isset($_POST['submit'])) {
$title=$_POST['title'];
if(strlen($title)<8)
{
//codes to handle error
}

$body=$_POST['body'];
if(strlen($body)<80)
{
//codes to handle error
}
$category=$_POST['category'];
$title = mysql_real_escape_string($title);
$body = mysql_real_escape_string($body);
$posted_by = $user;
$bio = $bio;
$id=$_SESSION['id'];
$date = date ('Y-m-d');
$body = htmlentities($body);
if ($title && $body && $category) {
if(strlen($title)>8 && strlen($body>80))
{

$query = mysql_query("INSERT INTO blogs (id, title, body, posted_by, bio, category_id, posted) VALUES ('$id', '$title', '$body', '$posted_by','$bio', '$category', '$date')");
}
else {
$query = 0;
}
if($query) {
echo "posted";

}
else {
echo "error";
}
}else {
echo "data missing";
}

关于php - 设置帖子的最小字符长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32547851/

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