Can't Pass Value from Form to Controller |
[eluser]Chris CMC[/eluser]
I'm a noobie and think I'm making another basic mistake. For some reason, all my fields are inputting as '0' when they enter the database. I'm assuming that means the connection is working, and the model is actually inputting data. But somewhere in that process both the strings and integers are reduced to the integer 0. Here's my view: Code: <?php Here's my controller: Code: function input() { Here's my model: Code: function addOne($data) One last thing I should note is I have 10 fields in the ci_entry table, which is why I used 'set' for the four fields I'm actually using. Any idea what's going on? I've been banging my head the last two hours on this and can't figure it out. (Again, I'm a noob ... my apologies for taking your time if this is obvious!)
[eluser]bretticus[/eluser]
Looks fine to me at first glance (besides a missing closing form tag perhaps.) Use the profiler class to get helpful information such as post data and database queries that were ran.
[eluser]squarebones[/eluser]
Code: function addOne($data) Assigns the data to the correct rows without your intervention as long as the data values match the names of the rows in the table. Returns the id of the newly created row in case you need it for some reference (added bonus).
[eluser]Chris CMC[/eluser]
Thanks Brett, the profiler is helpful. Here's the relevant part: Quote:URI STRING The problem is that my form isn't passing the values to the controller. I just checked this again, by defining $data directly in the controller and passing it to the model. That works, so it's clearly a problem of getting the form to pass values to the controller. With that I'm a bit stumped. I've checked the first parameter of form_open against the URI String above about ten times, but they're each what they should be. Did I not configure something write in my install? Do I need to add a parameter to any of the form fields? Any ideas?
[eluser]Chris CMC[/eluser]
Here's the HTML: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" Anything jump out at you? Also: squarebones, thanks for the tip. Once I figure out how to get the data to the model, I'll clean it up accordingly. Thanks.
[eluser]Chris CMC[/eluser]
Nice catch, I just added the close tag. Unfortunately though it hasn't solved the main problem. Still getting the same result from the profiler: "POST DATA: no POST data exists"
[eluser]ciGR[/eluser]
All looks fine. But try to change your method name from input to another name. Because when in your controller you call $this->input->post(); maybe try to call your method $this->input and not the CI class $this->input I'm not sure that's the problem, but give it a try.
[eluser]Dolrich[/eluser]
In your controller. The input function, there is an excess comma. It shouldbe like this. Code: function input() { |
Welcome Guest, Not a member yet? Register Sign In |