Welcome Guest, Not a member yet? Register   Sign In
Blog Input Form
#1

Hello,

I already try inputing certain information into the blog and form hoping that my input will be place into the database.  but I have not seen any text that I input in the database.  Can anyone help me fix my codes so that I could input the text in the database.  Thanks in advance.


A Database Error Occurred
Error Number: 1048
Column 'date' cannot be null
INSERT INTO `blog` (`date`, `title`, `content`) VALUES (NULL, 'Title', '\r\nContent\r\n')
Filename: C:/Program Files (x86)/EasyPHP-Devserver-16.1/eds-www/blog/system/database/DB_driver.php
Line Number: 691

May 2016

Su  Mo  Tu  We  Th  Fr  Sa

Date : 6 May 2016
 

Upload :  [Browse]

Title :  [Title]

Content :  [Content]


[ Submit ]



views/blog.php

PHP Code:
<html>

<
title>Blog</title>

<
br>

<
h1>BLOG</h1>


<?
php echo $this->calendar->generate(); ?>

<?php $blogs $this->blog_model->select_blog();  ?>

<?php foreach ($blogs as $row) : ?>

    <i><?php echo $row->date?></i><br><br>
    <b><?php echo $row->title?></b><br><br>
    <?php echo $row->content?><br><br><br>
    
<?php endforeach; ?>


</html> 


models/blog_model.php

PHP Code:
public function insert_blog()
 
       {
 
                                              
                $data 
= array(
                    
'date'  => $this->input->post(date),
                    
'title' => $this->input->post('title'),
                    
'content' => $this->input->post('content')                    
                );

                return 
$this->db->insert('blog'$data);
 
       
" If I looks more intelligence please increase my reputation."
Reply
#2

(05-05-2016, 10:00 PM)davy_yg Wrote: Hello,

I already try inputing certain information into the blog and form hoping that my input will be place into the database.  but I have not seen any text that I input in the database.  Can anyone help me fix my codes so that I could input the text in the database.  Thanks in advance.


A Database Error Occurred
Error Number: 1048
Column 'date' cannot be null
INSERT INTO `blog` (`date`, `title`, `content`) VALUES (NULL, 'Title', '\r\nContent\r\n')
Filename: C:/Program Files (x86)/EasyPHP-Devserver-16.1/eds-www/blog/system/database/DB_driver.php
Line Number: 691

May 2016

Su  Mo  Tu  We  Th  Fr  Sa

Date : 6 May 2016
 

Upload :  [Browse]

Title :  [Title]

Content :  [Content]


[ Submit ]



views/blog.php

PHP Code:
<html>

<
title>Blog</title>

<
br>

<
h1>BLOG</h1>


<?
php echo $this->calendar->generate(); ?>

<?php $blogs $this->blog_model->select_blog();  ?>

<?php foreach ($blogs as $row) : ?>

 <i><?php echo $row->date?></i><br><br>
 <b><?php echo $row->title?></b><br><br>
 <?php echo $row->content?><br><br><br>
 
<?php endforeach; ?>


</html> 


models/blog_model.php

PHP Code:
public function insert_blog()
 
       {
 
                              
 $data 
= array(
 
'date'  => $this->input->post(date),
 
'title' => $this->input->post('title'),
 
'content' => $this->input->post('content'
 );

 return 
$this->db->insert('blog'$data);
 
       

Are you using datetime in your table? Lets get that straight first.
Reply
#3

(This post was last modified: 05-06-2016, 12:56 AM by keulu.)

date is not recognized.
use
PHP Code:
date('Y-m-d H:i:s'
Reply
#4

fix this line in your model:
'date' => $this->input->post(date),
Reply
#5

You probably want to insert the current date/time. This is how to do that:
PHP Code:
$data = array(
 
'date'  => date('Y-m-d H:i:s'),
 
'title' => $this->input->post('title'),
 
'content' => $this->input->post('content'
 ); 

If the date is actually posted by your form, in a field named 'date', then the value is in $this->input->post('date');
Reply




Theme © iAndrew 2016 - Forum software by © MyBB