Storing Multiple Checkbox Data in MySQL Database with PHP

前端 未结 4 853
-上瘾入骨i
-上瘾入骨i 2021-02-10 05:30

I want to have multiple checkbox values be stored into one field in a database. (Ex. 1, 24,56,100). I am wanting to know how I can make this happen, and how does PHP read thes

4条回答
  •  星月不相逢
    2021-02-10 05:57

    first create database:

    create table employee(id int(10) not null, name varchar(20), hobbie varchar(20),
         worked varchar(20), primary key(id));
    

    after that create an html page like that:

       
      
      
      
      Untitled Document
     
    
     
     
     
    Name:


    Which you do you want to likes?
    Books
    Movies
    Sports
    Games
    Travelling
    worked:

    after that we have do mysql connect.php

     
    

    after that we have to create an check.php like that ok

    You didn't select any any hobby.

    \n"); } else { $N = count($hobb); echo("

    You selected $N Hobbies(s): "); for($i=0; $i < $N; $i++) { $var1=$hobb[$i]; include ('connect.php'); $table = "INSERT INTO employee (name, hobbies, worked) ". "VALUES ('$name', '$var1', '$worked')"; mysql_query($table) or die(mysql_error()); $inserted_fid = mysql_insert_id(); mysql_close(); } echo "successfully uploaded!.."; } } else { echo "error please check ur code"; }

提交回复
热议问题