Welcome Guest, Not a member yet? Register   Sign In
adding data to the database
#2

(This post was last modified: 02-16-2015, 11:19 PM by RobertSF.)

Hi Ben. Are you autoloading the database library and your model file? I don't autoload on my own system, so when I copied your code to my system, I could only get it to work after inserting '$this->load->database; and '$this->load->model('site_model') at the appropriate places. If you are not autoloading, consider using constructor methods in your controller and model files. Do you have the docs for Codeigniter? They explain how to do that.

Once I added those lines, I was able to add entries to the table. However, there was still one small error. In your view file, you have
Code:
<label for="title">Title</label>
<input type="text" id="title" id="title" />

Because that textbox has no name attribute, the contents never get sent to Codeigniter via the $_POST variable, so when you go 'title' => $this->input->post('title') , you get FALSE returned instead of the title.

Is your PHP set up to report errors to the screen? Ideally, your development system would have error reporting turned on to the max in your PHP.INI file. The line looks like error_reporting = E_ALL.

Finally, you're using the same id="content" on two different controls. That's not causing your problem, but it might cause styling problems. The id attribute must be unique, used only once.

Let me know if the above solves your problem. Smile
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply


Messages In This Thread
adding data to the database - by Ben - 02-16-2015, 09:48 PM
RE: adding data to the database - by RobertSF - 02-16-2015, 11:07 PM
RE: adding data to the database - by Ben - 02-17-2015, 11:55 AM
RE: adding data to the database - by RobertSF - 02-17-2015, 02:39 PM



Theme © iAndrew 2016 - Forum software by © MyBB