首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >提交表格不会输入某些类型的数据。

问提交表格不会输入某些类型的数据。
EN

Stack Overflow用户
提问于 2013-09-30 13:57:20
回答 1查看 43关注 0票数 0

我很久以前就创建了这段代码,在日常使用之后,我开始注意到它没有输入特定类型的数据。例如,当我从http://en.wikipedia.org/wiki/Pangram复制所有的字谜时,它将无法工作,它将提取定义的错误“提交数据的错误”。我没有从PHP本身得到“真正的”错误。为什么这个不能正常工作?谢谢你的帮助。视距变量..。

$db = mysqli_connect('localhost','xx','xxx','xxxx') or die('error with connection');

提交制度

代码语言:javascript
复制
session_start();
if(!isset($_SESSION['user_id'])){
    header('Location: login.php');
    exit();
}
include('../includes/db_connect.php');
if(isset($_POST['submit'])){
    $newTitle = $_POST['newTitle'];
    $newPost = $_POST['newPost'];
    $newPostPreview = $_POST['newPostPreview'];
    $newCategory = $_POST['newCategory'];
    if(!empty($newPost))
        if(!empty($newTitle))
            if(!empty($newPostPreview)){
    $sql="INSERT INTO posts  (title, body, post_preview, category_id, posted)
VALUES('$newTitle', '$newPost', '$newPostPreview', '$newCategory', (now()))";
    $query = $db->query($sql);
    if($query){
            echo "Post entered to database";
        }else{
            echo "Error Submitting the data";
        }
    }else{
        echo "One Or more Required forms was not filled!";
    }
}

文本区域和其他东西

代码语言:javascript
复制
    <br><textarea name="newPostPreview" placeholder="Post Preview(Will Be Displayed on the Index Page)" cols="100"  rows="10"/></textarea>
<br><textarea name="newPost" placeholder="Post Text" cols="100"  rows="10"/></textarea><br>

<input type="submit" name="submit" value="submit"/>    

请注意,它只适用于纯文本和英语内容,但其他时候,它不会因为外观原因而工作(只是普通的英文帖子中没有格式,不会提交。)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-30 14:17:17

这类问题通常出现在尝试插入具有特殊characters.So的字符串时,我建议在access post值使用php函数mysql_real_escape_string()时使用:-

$newTitle =mysql_real_escape_string($_POST‘’newTitle‘);

代码语言:javascript
复制
$newPost = mysql_real_escape_string($_POST['newPost']);

$newPostPreview = mysql_real_escape_string($_POST['newPostPreview']);

$newCategory = mysql_real_escape_string($_POST['newCategory']);

希望这能起作用

谢谢

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19096128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档