Welcome Guest, Not a member yet? Register   Sign In
Update Array values to DB
#6

(This post was last modified: 10-11-2019, 07:13 AM by Wouter60.)

Quote:$sql_query1 = "UPDATE movies_info SET `movie_name`='$movie_name',`movie_original_name`='$movie_original_name',`movie_image`='$target',
`movie_description`='$movie_description',`movie_stars`='$movie_stars',`movie_director`='$movie_director',
`movie_trailer`='$movie_trailer',`release_date`='$release_date',`release_year`='$release_year',`movie_genre`='$movie_genre',
`movie_rating`='$movie_rating',`movie_country`='$movie_country',`movie_runtime`='$movie_runtime',
`is_featured`='$is_featured' WHERE `movie_id`='$movie_id'";

I see a few problems.
First of all, if you enclose a variable in single quotes, it will be taken as a literal string, not as it's value.
In CI, you can pass an associated array to the $this->db->update() function, like this:
PHP Code:
$data = array(
  'movie_name' => $movie_name,
  'movie_original_name' => $movie_original_name,
  'movie_director' => $movie_director,
);
$this->db->where('id'$movie_id)->update('table_name'$data); 
(It works the same if you pass the $data to your model).

Another thing is how you convert the array of countries to a comma separated string.
You can use php's implode function:
PHP Code:
$movie_country implode(',' $this->input->post('movie_country')); 
If you read it back from your database, use explode() to convert it to an array.

A better method for storing an array into a table field in your database is php's serialize:
PHP Code:
$movie_country serialize($this->input->post('movie_country')); 
Serialize doesn't only store the array's values, but also the keys, variable-types and string-lengths. It will code all this information into a string.
Use unserialize() to convert it back to an array.
Reply


Messages In This Thread
Update Array values to DB - by manigopal - 10-09-2019, 05:25 AM
RE: Update Array values to DB - by manigopal - 10-09-2019, 06:37 AM
RE: Update Array values to DB - by php_rocs - 10-09-2019, 07:45 AM
RE: Update Array values to DB - by manigopal - 10-09-2019, 10:22 PM
RE: Update Array values to DB - by php_rocs - 10-10-2019, 08:35 AM
RE: Update Array values to DB - by Wouter60 - 10-11-2019, 05:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB