Welcome Guest, Not a member yet? Register   Sign In
How to send array from view to model
#1

how to submit a form containing an array in codeigniter 

<form method="post" action="collect_vals.php">
    <div><input type="text" name="mytext[]"></div>
</div>
</form>
E-surf
Reply
#2

This is not properly a CodeIgniter problem, but more a general PHP question. See

- https://www.w3schools.com/php/php_forms.asp
- https://stackoverflow.com/questions/3314...-php-array
- http://comp4711.jlparry.com/display/less...4-handling
Reply
#3

Am not sure u understand my question 

Here the error am having anyway 

this my error 

A PHP Error was encountered
Severity: Notice

Message: Array to string conversion

Filename: database/DB_query_builder.php

Line Number: 683

Backtrace:

File: /var/www/html/esurf/application/models/Bs_admin_model.php
Line: 482
Function: where

File: /var/www/html/esurf/application/controllers/hod/Users.php
Line: 407
Function: get_all_course_assign_by_search

File: /var/www/html/esurf/index.php
Line: 316
Function: require_once
E-surf
Reply
#4

Your original post made no mention of an error.
From the backtrace, it looks like line 482 in Bs_admin_model.php is calling the query builder's where() with one of the arguments being an array when a string is expected.
Reply
#5

I know that I told u Am passing an array variable to my model 
That y I ask for help on the proper way to pass array data in codeigniter
E-surf
Reply
#6

(This post was last modified: 06-03-2018, 04:21 AM by InsiteFX. Edit Reason: added some examples )

The Query Builder where expects a string as admin said, if you want to pass an array
you need to assign the array index that you want to use in the where clause to a string
property and then use it in the where clause.

PHP Code:
foreach($_POST["array_name"] as $key => $value)
{
 
   $data[$key] = $value;
}

// or

$data array_map(null$_POST["array_name"]); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

(06-03-2018, 03:49 AM)InsiteFX Wrote: The Query Builder where expects a string as admin said, if you want to pass an array
you need to assign the array index that you want to use in the where clause to a string
property and then use it in the where clause.

PHP Code:
foreach($_POST["array_name"] as $key => $value)
{
 
   $data[$key] = $value;
}

// or

$data array_map(null$_POST["array_name"]); 

Ok I give it a try
E-surf
Reply




Theme © iAndrew 2016 - Forum software by © MyBB