I'm doing maintenance on a website that another developer created. The client was having some data display issues and I narrowed it down to their input form, or more specifically, the POST data processing. All the fields are TEXTAREA fields and the controller function looks like this:
85 $data=array(
86 'f_location'=>$this->input->post('flocation'),
87 's_location'=>$this->input->post('slocation'),
88 't_location'=>$this->input->post('tlocation'),
89 'forthlocation'=>$this->input->post('forthlocation'),
90 'fifthlocation'=>$this->input->post('fifthlocation'),
91 'sixthlocation'=>$this->input->post('sixthlocation')
92 );
93 $query=$this->admin_model->updatelocation($data);
The updatelocation function in the model is:
54 function updatelocation($data){
55 $query=$this->db->where('id','1');
56 $query=$this->db->update('location',$data);
57
58 if($query){
59 return true;
60 }else{
61 return false;
62 }
63 }
For whatever reason, whenever I submit any sort of text data through the form, it stores it in the database as a '0'. When I submit integers, it stores the integers directly. To make matters weirder, I just tried to do a print_r($_POST) inside the controller function and if there is any integers, all data is accepted, including text. If all of the fields are text, the $_POST array is empty.
I am not a pro on CodeIgniter by any means, but I can at least work my way around it, and I can't figure this one out.
Here's the list of what I've checked so far:
- XSS Filtering is off
- Form Validation is not being used
- Database collation/character set doesn't affect it (currently utf8_unicode_ci)
- Database data type is set to text
- Tried adding trailing / to form action
- db_debug is enabled in config/database.php (no errors reported)
I'm sure there's a few other things I've tried that I can't think of right now. Oh, and one other weird thing. I have a local development server in my house. When I download the entire codebase to that server, everything works fine. Literally the only change I make is the baseurl in the config so it works locally for me, and then everything works just fine: text, integers, everything. It's only on the remote hosted site that the text won't go through. Any help is appreciated. I'm thoroughly stumped.
EDIT 1: Did some further testing with a var_dump($this->input->post()) as the first action in the controller. When all 6 input fields are text, it returns bool(false). It's as if CodeIgniter isn't recognizing the form data if there is text.
The HTML of the form is:
<form name="addlocation" action="<<<redacted>>>" method="post">
<h2>Add Location data</h2>
<p><textarea style="margin-left:5px;" rows="3" cols="4" required placeholder="Firstlocation" name="flocation">0</textarea> </p>
<p><textarea style="margin-left:5px;" rows="3" cols="4" required placeholder="Secondlocation" name="slocation">0</textarea></p>
<p><textarea style="margin-left:5px;" rows="3" cols="4" required placeholder="Thirdlocation" name="tlocation">0</textarea></p>
<p><textarea style="margin-left:5px;" rows="3" cols="4" required placeholder="Forthlocation" name="forthlocation">0</textarea></p>
<p><textarea style="margin-left:5px;" rows="3" cols="4" required placeholder="Fifthlocation" name="fifthlocation">0</textarea></p>
<p><textarea style="margin-left:5px;" rows="3" cols="4" required placeholder="Sixthlocation" name="sixthlocation">0</textarea></p>
<button class="btn btn-success" type="Submit" value="Submit">Update</button1>
</form>
I've tried removing the required, with no luck. The '0' is being pulled from the database as it is the current value. Values are being written to the database, just incorrectly.