473,324 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Form With Selection to MYSQL - PHP

1
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:

Expand|Select|Wrap|Line Numbers
  1. <form action="insertcheckbox.php" method="POST">
  2.  
  3.         <div class="modal-body">
  4.  
  5.             <div class="form-group">
  6.                 <label> Ime i Prezime </label>
  7.                 <input type="text" name="ime" class="form-control" placeholder="Upišite Ime i Prezime">
  8.             </div>
  9.             <div class="form-group">
  10.                 <label> Upišite Spol </label>
  11.                 <input type="text" name="spol" class="form-control" placeholder="Upišite Spol (M/Ž)">
  12.             </div>
  13.             <div class="form-group">
  14.                 <label>Grad</label>
  15.                 <input style="font-style: #f89900" type="text" name="grad" class="form-control" placeholder="Upišite Grad iz kojeg dolazi Student">
  16.             </div>
  17.             <div class="form-group">
  18.                 <label>Telefon</label>
  19.                 <input style="font-style: #f89900" type="text" name="tel" class="form-control" placeholder="Upišite Telefon">
  20.             </div>
  21.             <div class="form-group">
  22.                 <label>Email</label>
  23.                 <input style="font-style: #f89900" type="email" name="email" class="form-control" placeholder="Upišite Email">
  24.             </div>
  25.             <div class="form-group">
  26.                 <label>Uzrast</label>
  27.                 <input style="font-style: #f89900" type="text" name="uzrast" class="form-control" placeholder="Upišite Uzrast">
  28.             </div>
  29.             <div class="form-group">
  30.                 <label>Škola</label>
  31.                 <input style="font-style: #f89900" type="text" name="skola" class="form-control" placeholder="Upišite Obrazovnu Ustanovu">
  32.             </div>
  33.  
  34.             <div class="form-group">
  35.               <label>Izaberite Programe sa liste</label>
  36.              <select name="naziv[]" id="naziv" class="form-control action" multiple="">
  37.               <option disabled selected>-- Izaberi Program --</option>
  38.               <?php
  39.                 include "config/database.php";  // Using database connection file here
  40.                 $records = mysqli_query($conn, "SELECT naziv FROM program");  // Use select query here 
  41.  
  42.                 while($data = mysqli_fetch_array($records))
  43.                 {
  44.                 echo "<option value='". $data['naziv'] ."'>" .$data['naziv'] ."</option>";  // displaying data in option menu
  45.                 } 
  46.               ?>  
  47.             </select> 
  48.             </div>
  49.         </div>
  50.         <div class="modal-footer">
  51.             <button type="button" class="btn btn-secondary" data-dismiss="modal">Zatvori</button>
  52.             <button type="submit" value="submit" name="registerbtn" class="btn btn-primary">Pošalji</button>
  53.         </div>
  54.       </form>
PHP FORM:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include_once 'config/database.php';
  3. if(isset($_POST['Register']))
  4. {  
  5.    $ime = $_POST['ime'];
  6.    $spol = $_POST['spol'];
  7.    $grad = $_POST['grad'];
  8.    $tel = $_POST['tel'];
  9.    $email = $_POST['email'];
  10.    $uzrast = $_POST['uzrast'];
  11.    $skola = $_POST['skola'];
  12.    $naziv = $_POST['naziv'];
  13.    $sql = "INSERT INTO students (ime, spol, grad, tel, email, uzrast, skola, naziv)
  14.    VALUES ('$ime','$spol','$grad','$tel', '$email', '$uzrast', '$skola', '$naziv')";
  15.    if (mysqli_query($conn, $sql)) {
  16.     echo "New record created successfully !";
  17.    } else {
  18.     echo "Error: " . $sql . "
  19. " . mysqli_error($conn);
  20.    }
  21.    mysqli_close($conn);
  22. }
  23. ?>
Jun 29 '20 #1
1 3855
Ishan Shah
47 32bit
You are Storing multiple select box values to an array so, save the values to the database using comma-separated.

Expand|Select|Wrap|Line Numbers
  1. $naziv = implode(',', $_POST['naziv']);
  2.  
Jul 10 '20 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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...
4
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
4
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...
32
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...
0
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...
1
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...
1
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);
2
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
1
isladogs
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...
0
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...
0
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...
1
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)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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....
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.