我很久以前就创建了这段代码,在日常使用之后,我开始注意到它没有输入特定类型的数据。例如,当我从http://en.wikipedia.org/wiki/Pangram复制所有的字谜时,它将无法工作,它将提取定义的错误“提交数据的错误”。我没有从PHP本身得到“真正的”错误。为什么这个不能正常工作?谢谢你的帮助。视距变量..。
$db = mysqli_connect('localhost','xx','xxx','xxxx') or die('error with connection');
提交制度
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!";
}
}文本区域和其他东西
<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"/> 请注意,它只适用于纯文本和英语内容,但其他时候,它不会因为外观原因而工作(只是普通的英文帖子中没有格式,不会提交。)
发布于 2013-09-30 14:17:17
这类问题通常出现在尝试插入具有特殊characters.So的字符串时,我建议在access post值使用php函数mysql_real_escape_string()时使用:-
$newTitle =mysql_real_escape_string($_POST‘’newTitle‘);
$newPost = mysql_real_escape_string($_POST['newPost']);
$newPostPreview = mysql_real_escape_string($_POST['newPostPreview']);
$newCategory = mysql_real_escape_string($_POST['newCategory']);希望这能起作用
谢谢
https://stackoverflow.com/questions/19096128
复制相似问题