My problem is inserting new data from html form from element <input type = checkbox>
, other input field html form php script into mysql table inserted correctly, without errors.
First html form snippet - this is my current checkbox (with more options):
<input id="element_5" type="checkbox" name= "skupiny_rp[]" value="C" checked> C <br>
<input id="element_5" type="checkbox" name= "skupiny_rp[]" value="CE" > CE <br>
<input id="element_5" type="checkbox" name= "skupiny_rp[]" value="D"> D <br>
<input id="element_5" type="checkbox" name= "skupiny_rp[]" value="DE"> DE <br>
I used array to store more values from the checkbox.
My idea was as follows:
I wanted to use the procedure that I used when inserting these values into a csv file - this procedure worked, here when inserting into MySQL table is not working. This array skupiny_rp[]
I converted this field using php the implode () php function and put it in csv. But to insert into mysql table from implode function for mysql doesn't work.
Here's a php and sql snippet: all input fields of the html form before being inserted into the mysql table treated using mysqli_real_escape_string()
here prepare sql query
$query = "INSERT INTO skoleni (jmeno, prijmeni, narozen, ulice_cp,
mesto, psc, zeme, cislo_rp, skupina_rp,email,telefon,
termin_skoleni)
VALUES ('$jmeno', '$prijmeni', '$narozen', '$ulice_cp',
'$mesto', '$psc','$zeme', '$cislo_rp', '$skupina_rp',
'$email', '$telefon', '$termin')";
And here the execution of the query and its verification of success:
if (mysqli_query($SQLconn,$query)):
echo "Záznam vytvořen.";
close($SQLconn);
else:
echo "Vytvoření záznamu selhalo." ;
endif;
This source code works almost correctly. But displaying the values from the html checkbox seems to me unsolvable, can someone advise how to display the mysql table all selected values from skupiny_rp[]
in the MySQL table.
Here's the configuration table in Mysql:
CREATE TABLE skoleni (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
registrovan TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
jmeno VARCHAR(10) NOT NULL,
prijmeni VARCHAR(30) NOT NULL,
narozen VARCHAR(20) NOT NULL,
ulice_cp VARCHAR(255) NOT NULL,
mesto VARCHAR(50) NOT NULL,
psc VARCHAR(5) NOT NULL,
zeme VARCHAR(50) NOT NULL,
cislo_rp VARCHAR(10) NOT NULL,
skupina_rp VARCHAR(10) NOT NULL,
email VARCHAR(50) NOT NULL,
telefon VARCHAR(9) NOT NULL,
termin_skoleni VARCHAR(50) NOT NULL)