I've been trying to figure out what have I done wrong in a piece of code I'm working on, but with no luck. It's surely something stupid here or there, and I really need your help.
Please see the code below:
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...";
}
}
}
The problem: Whenever I execute the insert into query, I keep getting the "Something went wrong, try again later..."