i have searched over the net for this query and I could find some on this platform but they are not well explanatory to me. I have a table which holds message and the table also contains username column to track the messenger using login session but every time I tried to insert a message i received Field 'username' doesn't have a default value. here is my code:
<?php
session_start();
if(!isset($_SESSION['user_name']) || (trim($_SESSION['user_name']) == '')) {
header("location: ../login");
exit();
}else{
$user= $_SESSION['user_name'];
if(!empty($_POST['message'])) {
include_once 'includes/config.php';
include_once 'includes/security.php';
include_once 'includes/smileys.php';
$message = clean(mysql_real_escape_string($_POST['message']));
$message = special_chars($message);
$time = time();
//getting image link
if(!empty($_POST['pic_url'])) {
$image = strip_tags($_POST['pic_url']);
} else {
$image = '';
}
$git = '';
//getting video link
if(!empty($_POST['y_link'])) {
$video = fix_url(strip_tags($_POST['y_link']));
} else {
$video = '';
}
//insert into wall table
$query = mysql_query("INSERT INTO posts SET
post_desc = '$message',
image_url = '$image',
vid_url = '$video',
username = '',
git = '$user',
post_date = '$time')") or die(mysql_error());
$ins_id = mysql_insert_id();
?>
the sql table syntax:
CREATE TABLE `posts` (
`post_id` int(9) NOT NULL,
`post_desc` mediumtext NOT NULL,
`image_url` varchar(100) NOT NULL,
`vid_url` varchar(100) NOT NULL,
`username` varchar(100) NOT NULL,
`git` varchar(100) DEFAULT NULL,
`post_date` varchar(20) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;