I want to use this form with multiple select box to put data to database. I can put all data, but I can't put selections. What I am missing?
HTML FORM: - <form action="insertcheckbox.php" method="POST">
-
-
<div class="modal-body">
-
-
<div class="form-group">
-
<label> Ime i Prezime </label>
-
<input type="text" name="ime" class="form-control" placeholder="Upišite Ime i Prezime">
-
</div>
-
<div class="form-group">
-
<label> Upišite Spol </label>
-
<input type="text" name="spol" class="form-control" placeholder="Upišite Spol (M/Ž)">
-
</div>
-
<div class="form-group">
-
<label>Grad</label>
-
<input style="font-style: #f89900" type="text" name="grad" class="form-control" placeholder="Upišite Grad iz kojeg dolazi Student">
-
</div>
-
<div class="form-group">
-
<label>Telefon</label>
-
<input style="font-style: #f89900" type="text" name="tel" class="form-control" placeholder="Upišite Telefon">
-
</div>
-
<div class="form-group">
-
<label>Email</label>
-
<input style="font-style: #f89900" type="email" name="email" class="form-control" placeholder="Upišite Email">
-
</div>
-
<div class="form-group">
-
<label>Uzrast</label>
-
<input style="font-style: #f89900" type="text" name="uzrast" class="form-control" placeholder="Upišite Uzrast">
-
</div>
-
<div class="form-group">
-
<label>Škola</label>
-
<input style="font-style: #f89900" type="text" name="skola" class="form-control" placeholder="Upišite Obrazovnu Ustanovu">
-
</div>
-
-
<div class="form-group">
-
<label>Izaberite Programe sa liste</label>
-
<select name="naziv[]" id="naziv" class="form-control action" multiple="">
-
<option disabled selected>-- Izaberi Program --</option>
-
<?php
-
include "config/database.php"; // Using database connection file here
-
$records = mysqli_query($conn, "SELECT naziv FROM program"); // Use select query here
-
-
while($data = mysqli_fetch_array($records))
-
{
-
echo "<option value='". $data['naziv'] ."'>" .$data['naziv'] ."</option>"; // displaying data in option menu
-
}
-
?>
-
</select>
-
</div>
-
</div>
-
<div class="modal-footer">
-
<button type="button" class="btn btn-secondary" data-dismiss="modal">Zatvori</button>
-
<button type="submit" value="submit" name="registerbtn" class="btn btn-primary">Pošalji</button>
-
</div>
-
</form>
PHP FORM: - <?php
-
include_once 'config/database.php';
-
if(isset($_POST['Register']))
-
{
-
$ime = $_POST['ime'];
-
$spol = $_POST['spol'];
-
$grad = $_POST['grad'];
-
$tel = $_POST['tel'];
-
$email = $_POST['email'];
-
$uzrast = $_POST['uzrast'];
-
$skola = $_POST['skola'];
-
$naziv = $_POST['naziv'];
-
$sql = "INSERT INTO students (ime, spol, grad, tel, email, uzrast, skola, naziv)
-
VALUES ('$ime','$spol','$grad','$tel', '$email', '$uzrast', '$skola', '$naziv')";
-
if (mysqli_query($conn, $sql)) {
-
echo "New record created successfully !";
-
} else {
-
echo "Error: " . $sql . "
-
" . mysqli_error($conn);
-
}
-
mysqli_close($conn);
-
}
-
?>
1 3855
You are Storing multiple select box values to an array so, save the values to the database using comma-separated. -
$naziv = implode(',', $_POST['naziv']);
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: sammmista |
last post by:
hello experts,
Plz dont treat this as another newbie query , i did my homework but
still getting nowhere :( :( :(
Trying to learn PHP on Fedora core 1 (PHP 4.3,MySQL,HTTPD).Unable to
post data...
|
by: Lee David |
last post by:
How do I take a field from a form and store it on in a mySQL table?
TIA, Lee
|
by: Takeadoe |
last post by:
I recently asked the group for help on converting 3 numeric variables
to a new date variable. The DATESERIAL function below worked
perfectly! My question now relates to problems with this new...
|
by: fjm |
last post by:
Hi all, thanks for helping. I'm sure what I want to do is amongst the basic in php. I know ehat I need but I really don't where to begin.
What I have is a basic html form I have made consisting of...
|
by: vjayis |
last post by:
Hi
i got an error while my site gets loaded
Warning: mysql_query() : Unable to save result set in /path../includes/mysql.class.php on line 39
Error in Selection MySQL client ran out of memory...
|
by: Pazeh |
last post by:
Hello, a first timer here! stumbled upon one of the threads hear while searching on google & the feedback was awesome so I decided to jump in & ask my Q! I'm a newbie in AJAX, but I know my way...
|
by: jpenguin |
last post by:
This should be simple, but I'm stuck
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('joshdye', $con);
|
by: mike2098 |
last post by:
Hi I have a form with drop down boxes, tinymce and an ajax file up-loader I want to be able to submit the form and store all the data on a mysql db the trouble I have is I do not know how to...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shćllîpôpď 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |