Welcome Guest, Not a member yet? Register   Sign In
bug when setting $_POST array field to null?
#2

(10-26-2015, 02:16 PM)redjersey Wrote: I have some array fields in my html ie:
<input type="text" name="sold_for_price[]">
<input type="text" name="sold_for_price[]">
<input type="text" name="sold_for_price[]">
etc
which is not a mandatory fields, which  means the first one can be 12.00, second one can be empty, third one can be $1.25 etc

so when submitting to post it becomes:

$_POST['sold_for_price'] = array('12.00', '', '1.25');

however in mysql, money type cannot be empty string, so I'll have to manually convert it into null. ie:

if (strlen($_POST['sold_for_price'][i]) == 0) $_POST['sold_for_price'][i] = null; //if field is not entered, I'll change the value to null

however, changes won't reflect in $this->input->post('sold_for_price')[1]

but if I do: $_POST['some_other_money_field'] = null, then $this->input->post('some_other_money_field') will be null.


PHP Code:
$_POST['sold_for_price'] = array('12.00''0.00''1.25'); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
RE: bug when setting $_POST array field to null? - by InsiteFX - 10-26-2015, 05:41 PM



Theme © iAndrew 2016 - Forum software by © MyBB