簡體   English   中英

提交表格不會輸入某些數據

[英]Submission form will not enter certain kinds of data

我是在很久以前創建此代碼的,在每天使用后,我開始注意到它沒有輸入某些類型的數據。 例如,當我從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"/>    

請注意,它僅適用於純文本和英語內容,但有時它也不會由於沒有出現的原因而起作用(只是正常的英語帖子,其中不帶格式,不會提交..)

這種類型的問題通常是在您嘗試插入具有特殊字符的字符串時出現的。因此,我想建議在訪問后值使用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']);

希望這會起作用

謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM