PHP : insert multiple check boxes values into one MySQL column

前端 未结 5 1916
余生分开走
余生分开走 2020-12-14 13:30

I want to write a simple PHP function to insert values of 10 and 20 check boxes. Now, the issue is: should I insert all values in a single column of MySQL table or should I

5条回答
  •  盖世英雄少女心
    2020-12-14 14:06

    Try this whole example,

    Table Structure

    CREATE TABLE IF NOT EXISTS `games` (
      `id` int(12) NOT NULL AUTO_INCREMENT,
      `game_name` varchar(255) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
    
    0)
    {
        $my_value=mysql_fetch_assoc($run_qry);
        $my_stored_game=explode(',',$my_value['game_name']);
    }
    
    if(isset($submit))
    {
        $all_game_value = implode(",",$_POST['games']);
        if($total_found >0)
        {
            //update
            $upd_qry="UPDATE games SET game_name='".$all_game_value."'";
            mysql_query($upd_qry);
    
        }
        else
        {
            //insert
            $ins_qry="INSERT INTO games(game_name) VALUES('".$all_game_value."')";
            mysql_query($ins_qry);
        }
    }
    
    ?>
    
    Games You Like:
    >
    >
    >
    >
    >
    >
    >
    >

    this is just basic example and query i have added in this example, you can learn from this basic example and i think this is very useful for you... if useful than give correct answer for this solution

    Db Table Stored Output

    Form Output

提交回复
热议问题