Note that there are some explanatory texts on larger screens.

plurals
  1. POcodeigniter data is not getting inserted in database
    primarykey
    data
    text
    <p>Im a newbie in <a href="http://codeigniter.com/" rel="nofollow">CodeIgniter</a> and I just followed a tutorial for CRUD operations within framework but my data is not getting inserted in my database. Here is my code:</p> <p>Controller: site.php</p> <pre><code>&lt;?php class Site extends CI_Controller { function index() { $this-&gt;load-&gt;view("home"); } function create() { $data=array('title'=&gt;$this-&gt;input-&gt;post("title"), 'song'=&gt;$this-&gt;input-&gt;post("song") ); $this-&gt;site_model-&gt;add_record($data); $this-&gt;index(); } } </code></pre> <p>View: home.php</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;my page&lt;/title&gt; &lt;style type="text/css"&gt; input,label { display:block; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;?php echo form_open('site/create'); ?&gt; &lt;p&gt; &lt;label for="title"&gt;Title:&lt;/label&gt; &lt;input type="text" name="title" id="title" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="content"&gt;Song:&lt;/label&gt; &lt;input type="text" name="song" id="song" /&gt; &lt;/p&gt; &lt;p&gt; &lt;input type="submit" value="submit"/&gt; &lt;/p&gt; &lt;?php echo form_close(); ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Model: site_model.php</p> <pre><code>&lt;?php class site_model extends CI_Model { function getAll() { $q=$this-&gt;db-&gt;get('name'); return $q-&gt;result(); } function add_record($data) { $this-&gt;db-&gt;insert("name",$data); return; } function update_record($data) { $this-&gt;db-&gt;where("id",14); $this-&gt;db-&gt;update('name',$data); } function delete_row($data) { $this-&gt;db-&gt;where("id",$this-&gt;uri-&gt;segment(3)); $this-&gt;db-&gt;delete('name',$data); } } </code></pre> <p>My table name is <b>name</b> and I have 3 fields: id(auto_increment), title, and song. Help would be much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload