• 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
addnewsletters

#1
Hello,

I wonder why I have this error message?  I already try to add somethings here but it does not works!

views/addnewsletters.php



PHP Code:
<div class="widget-box">
                        <
div class="widget-title"><h5>Administrator</h5></div>
                        <
div class="widget-content">
                        
                        <
table border="0" style="width: 100%; height: 90px;">
                            <
tr>
                                <
td>Newsletter Name:</td>
                                <
td><input type="text" name="newsl_name"></td>
                            </
tr>
                            <
tr>
                                <
td>Newsletter Date:</td>
                                <
td><input type="text" name="newsl_date"></td>
                         
   </tr>
                            <
tr>
                                <
td>Newsletter Content:</td>
                                <
td><textarea name="newsl_content"></textarea></td>
                         
   </tr>    
                            <
tr>
                                <
td></td>
                                <
td><input type="submit" class="add" name="submit" value="SUBMIT" /></td>
                         
   </tr>    
                        </
table>            
                        </
div>
                    </
div



models/Mpages.php



PHP Code:
public function add_newsletters()
    {
                    
        
$data = array(
         
   'newsl_name' => $this->input->post('newsl_name'),
            
'newsl_date' => $this->input->post('newsl_date'),
            
'newsl_content' => $this->input->post('newsl_content')
        );
    
        return 
$this->db->insert('newsletter'$data);    
    
    } 


controllers/cpages.php



PHP Code:
public function addnewsletters() { 
    
        
$this->form_validation->set_rules('newsletter_name''Newsletter Name''required');
        
$this->form_validation->set_rules('newsletter_content''Newsletter Content''required');
                
        if(
$this->form_validation->run() === FALSE)
        {
            
            
$this->Mpages->add_newsletters();
            
$this->load->view('addnewsletterssuccess');
 
          
        
}
        else
        {
            
             
$this->load->view('addnewsletters');
             
        }    
    
    
    } 



A Database Error Occurred
Error Number: 1048
Column 'newsl_name' cannot be null
INSERT INTO `newsletter` (`newsl_name`, `newsl_date`, `newsl_content`) VALUES (NULL, NULL, NULL)
Filename: C:/Program Files (x86)/EasyPHP-Devserver-16.1/eds-www/CompanyGiondaCI/system/database/DB_driver.php
Line Number: 691
" If I looks more intelligence please increase my reputation."
Reply

#2
Maybe you need to add a <form> or form_open to tell it where to post to.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
Read the error message: your database record fields are not defined.
You don't have a form inside your view's HTML. I see no connection to your controller's addnewsletters method, and hence no way that input fields will be retrieved.
Your validation is checking the wrong input field names.
Reply

#4
This is the actual form.


views/addnewsletters.php


PHP Code:
<div class="span12">
                    
                    <?
php $this->load->library('form_validation'); ?>
                        
                    <?php echo validation_errors(); ?>
                        
                    <?php echo form_open('cpages/addnewsletters'); ?>
                    
                    <div class="widget-box">
                        <div class="widget-title"><h5>Administrator</h5></div>
                        <div class="widget-content">
                        
                        <table border="0" style="width: 100%; height: 90px;">
                            <tr>
                                <td>Newsletter Name:</td>
                                <td><input type="text" name="newsl_name"></td>
                            </tr>
                            <tr>
                                <td>Newsletter Date:</td>
                                <td><input type="text" name="newsl_date"></td>
                            </tr>
                            <tr>
                                <td>Newsletter Content:</td>
                                <td><textarea name="newsl_content"></textarea></td>
                            </tr>    
                            <tr>
                                <td></td>
                                <td><input type="submit" class="add" name="submit" value="SUBMIT" /></td>
                            </tr>    
                        </table>            
                        </div>
                    </div>                    
                </div> 
" If I looks more intelligence please increase my reputation."
Reply

#5
Why are you loading the library in a view? It should be loaded in the controller.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#6
Also... you are setting rules for "newsletter_name", "newsletter_content" and inserting values from "'newsl_name", "newsl_date" (and "newsl_content") input fields... Hmm... This is hard...
Reply

#7
(07-13-2016, 06:18 PM)davy_yg Wrote: This is the actual form.

I am afraid if the library won't function well in the controllers until the view.  


views/addnewsletters.php


PHP Code:
<div class="span12">
                    
                    <?
php $this->load->library('form_validation'); ?>
                        
                    <?php echo validation_errors(); ?>
                        
                    <?php echo form_open('cpages/addnewsletters'); ?>
                    
                    <div class="widget-box">
                        <div class="widget-title"><h5>Administrator</h5></div>
                        <div class="widget-content">
                        
                        <table border="0" style="width: 100%; height: 90px;">
                            <tr>
                                <td>Newsletter Name:</td>
                                <td><input type="text" name="newsl_name"></td>
                            </tr>
                            <tr>
                                <td>Newsletter Date:</td>
                                <td><input type="text" name="newsl_date"></td>
                            </tr>
                            <tr>
                                <td>Newsletter Content:</td>
                                <td><textarea name="newsl_content"></textarea></td>
                            </tr>    
                            <tr>
                                <td></td>
                                <td><input type="submit" class="add" name="submit" value="SUBMIT" /></td>
                            </tr>    
                        </table>            
                        </div>
                    </div>                    
                </div> 
" If I looks more intelligence please increase my reputation."
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.