我刚刚在我的数据库中添加了一个额外的列,以添加主题标签。但现在我的主题标签也保存在我的博客专栏中。有人可以帮我吗?

时间:2016-07-01 09:45:00

标签: database

<?php
session_start();
require_once "inc/package.inc.php";
include "connect.php";


//Ga er vanuit dat het formulier correct is ingevuld
$correct = true;

//Sla de waarden op in een variabel

$title = $_POST['title'];
if(isset($_POST['title']) && $_POST['title'] != ''){
    $title = filter_var($_POST['title'], FILTER_SANITIZE_STRING);
    $correct = true;
} else {
    echo "<p id='popupr'>Geef een titel!</p>";
    $correct = false; //Toch een foute waarde, onthou dit!
}

$blog = $_POST['reactie'];
if(isset($_POST['reactie']) && $_POST['reactie'] != ''){
    $blog = filter_var($_POST['reactie'], FILTER_SANITIZE_STRING);
    $correct = true;
} else {
    $correct = false; //Toch een foute waarde, onthou dit!
}

$mobiel = $_POST['mobiel'];
if(isset($_POST['mobiel']) && $_POST['mobiel'] != ''){
    $mobiel = filter_var($_POST['mobiel'], FILTER_SANITIZE_STRING);
    $correct = true;
} else {
    $correct = false; //Toch een foute waarde, onthou dit!
}

这是我将标签保存在名为'tweet'的变量中的地方。这是有效的。

$tweet = $_POST['hashtag'];
if(isset($_POST['hashtag']) && $_POST['hashtag'] != ''){
    $blog = filter_var($_POST['hashtag'], FILTER_SANITIZE_STRING);
    $correct = true;
} else {
    $correct = false; //Toch een foute waarde, onthou dit!
}

if(isset($_POST['btn_upload'])) {
    $img = $_FILES["file_img"];
    $filetmp = $_FILES["file_img"]["tmp_name"];
    $priority = 2;
    if (empty($img)) {
        $filename === null;
        $target === null;

    } else {
    $file = $_FILES["file_img"]["name"];
    $filetype = $_FILES["file_img"]["type"];
    // unieke toevoeging berekenen
    $uniqueId = uniqId();

    // een hash van het bestand, of data in bestand
    $hash    = sha1_file($filetmp);

    $filename = "image_".$uniqueId."-".$hash.".png";
    $target  = realPath("photo").DIRECTORY_SEPARATOR.$filename;

    move_uploaded_file($filetmp,$target);
    }

    $correct =  true;
} 

这是我检查是否所有内容都正确填充的地方。

//Was alles correct ingevuld?
if($correct){
    // voeg de reactie toe in de tabel blogs.
    $author = $_SESSION["name"];

    // voeg de reactie toe in de tabel blogs.
    include "datum.php";

我认为这里出了问题。它没有正确保存。它与我的数据库的顺序相同。在我的网站上,它显示了主题标签,而不是博客文章。这非常奇怪。

    try{
    $stmt = $connection->prepare("INSERT INTO blogs(author, date, title, blog, mobiel, hashtag, priority, img_name, img_path) VALUES (:author, :date, :title, :blog, :mobiel, :hashtag, :priority, '$filename', '$target')");
    $stmt->bindValue(':author', $author);
    $stmt->bindValue(':date', $datum);
    $stmt->bindValue(':title', $title);
    $stmt->bindValue(':blog', $blog);
    $stmt->bindValue(':mobiel', $mobiel);
    $stmt->bindValue(':hashtag', $tweet);
    $stmt->bindValue(':priority', $priority);
    }
    catch(PDOException $e)
    {
        echo $e;
    }
    $result = $stmt->execute();
    if(!$result) {
        print_r($stmt->errorInfo());
    } else {
        header('Location: index.php');
        exit;
    }

} else {
    //Er is ergens een foute waarde ingevoerd, geef de bezoeker de mogelijkheid om terug te gaan
    echo "<p>Er is een foute waarde ingevoerd, <a href=\"javascript:history.back();\">ga terug</a>.</p>";
} 

?>

对不起我的英语,我还在学习。

1 个答案:

答案 0 :(得分:0)

您正在使用$blog的内容定义变量$_POST['hashtag']并将其插入blog列,因此您将获得其中的#标签值。

你需要在这里解决它:

if(isset($_POST['hashtag']) && $_POST['hashtag'] != ''){
    $blog = filter_var($_POST['hashtag'], FILTER_SANITIZE_STRING);
    $correct = true;
} else {
    $correct = false; //Toch een foute waarde, onthou dit!
}