无法查询INSERT INTO数据库

时间:2017-04-19 13:56:19

标签: php mysql insert-into

我一直试图弄清楚我在一段代码中做错了什么,但没有运气。这里或那里肯定是个蠢事,我真的需要你的帮助。

请参阅以下代码:

require_once('inc\dbh.php');
include_once('inc\functions.php');

session_start();
if(!isset($_SESSION['user'])){
header("location:index.php");
}

$error = false;

if($_SERVER['REQUEST_METHOD'] == "POST") {
$title = sqlinjection($_POST['title']);
$details = sqlinjection($_POST['details']);
$date = strftime("%B %d, %Y"); //date
$time = strftime("%X"); //time
$owner = $_SESSION['user'];
$public = $_POST['public'];

// basic title validation
if (empty($title)) {
    $error = true;
    $titleerror = "<li>Please enter a board title.</li>";
} else if (strlen($title) < 5) {
    $error = true;
    $titleerror = "<li>Title must have atleat 5 characters.</li>";
} 

// basic details validation
if (empty($details)) {
    $error = true;
    $detailserror = "<li>Please enter a board detail.</li>";
} else if (strlen($details) < 55) {
    $error = true;
    $detailserror = "<li>Details must have atleat 55 characters.</li>";
}

// basic public validation
if (empty($public)) {
    $error = true;
    $publicerror = "<li>Please choose your board's privacy.</li>";
} 

// if there's no error, continue to add board
if( !$error ) {

    $query = "INSERT INTO boards('board_title', 'board_details', 'board_date_posted', 'board_time_posted', 'board_public') VALUES ('$title','$details',$date','$time','$public')";
    $res = mysql_query($query);

    if ($res) {
        $errMSG = "Successfully added.";
        unset($title);
        unset($details);
        unset($public);
    } else {
        $errMSG = "Something went wrong, try again later..."; 
    }

}

}

问题:每当我执行插入到查询中时,我都会得到&#34;出错了,稍后再试......&#34;

0 个答案:

没有答案