选择多个选项中的几个条目在数据库中为空

时间:2019-02-08 12:59:43

标签: php html mysql

我创建了一个表单,用户可以在其中输入数据并将其存储在数据库中。问题是“事件列”中的几个条目是“选择多个”选项,而某些条目则为空。 我不确定代码是否错误是服务器问题。任何帮助表示赞赏!

修改过的Register.html

 <form name="myform" action="check.php" method="post" onsubmit="return validateForm()">
<div class="form-group">
  <label for="Name">Name:</label>
  <input type="text" class="form-control" id="name" placeholder="Enter name" name="name" required>
</div>

     <div class="form-group">
  <label for="Email">Email:</label>
  <input type="email" class="form-control" id="email" placeholder="Enter email" name="email" required>
</div>

        <div class="form-group">
  <label for="Email">Mobile:</label>
  <input type="text" class="form-control" id="mobile" placeholder="Enter Mobile " name="mobile" required>
</div>

<div class="form-group">
  <label for="College">College:</label>
  <select id="cll" class="form-control" name="coll" required>
    <option value="IITM">IITM</option>
    <option value="IINTM">IINTM</option>
    <option value="Indraprastha">Indraprastha</option>
    <option value="Alumni">Alumni</option>
    <option value="Others">Others</option>
  </select>
</div>

  <div class="form-group">
  <label for="College">Course:</label>
  <select id="cour" class="form-control" name="course" required>
    <option value="BBA">BBA</option>
    <option value="BCA">BCA</option>
    <option value="B.Com">B.Com</option>
    <option value="MCA">MCA</option>
    <option value="MBA">MBA</option>
  </select>
</div>

   <div class="form-group">
  <label for="College">College:</label>
  <input type="text" class="form-control" id="college" placeholder="Enter College Name" name="college" required>
</div>

<div class="radio">
<label><input type="checkbox" onchange="swapConfig(this)" name="q1" id="production" value="individual">Individual</label>

       组

<div id="productionSettings">
  <label for="sell">Individual Events</label>
  <select class="form-control" id="indi" name="events[]" multiple required>
    <option value="Solo Singing">Solo Singing</option>
    <option value="Solo Dance">Solo Dance</option>
    <option value="Beat Boxing">Beat Boxing</option>
    <option value="Mono Acting">Mono Acting</option>
    <option value="Photography">Photography</option> 
    <option value="Just a minute">Just a minute</option>  
  </select>
</div>
  <div id="alphaSettings">
  <label for="sell">Group Events</label>
  <select class="form-control" name="events[]" id="grp" multiple required>
    <option value="Group Singing">Group Singing</option>
    <option value="Nach Baliye">Nach Baliye</option>
    <option value="Ad Mad">Ad Mad</option>
    <option value="Pubg Tournament">Pubg Tournament</option>
    <option value="Pictionary">Pictionary</option>
    <option value="Rangoli">Rangoli</option>
    <option value="Nukkad Natak">Nukkad Natak</option>
    <option value="Cooking Without Fire">Cooking Without Fire</option>
    <option value="Quiz">Quiz</option>
    <option value="Murder Investigation">Murder Investigation</option>
    <option value="Mr And Miss Fiesta">Mr And Miss Fiesta</option>
    <option value="IPL Auction">IPL Auction</option>
    <option value="Group Dance">Group Dance</option>
  </select>
</div>
<div id="nunSettings" style="display: none">
 </div>

<div class="checkbox">
  <label><input type="checkbox" name="remember"> Remember me</label>
</div>
<button type="submit" name="submit" value="submit" class="btn btn-dark">Submit</button>

编辑后的store.php

<?php

$link = mysqli_connect("localhost", "iitmfies_admin", "pass", "iitmfies_first");

// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}

// Escape user inputs for security
$name = mysqli_real_escape_string($link, $_REQUEST['name']);
$email = mysqli_real_escape_string($link, $_REQUEST['email']);
$mobile=$_POST['mobile'];
$college2=$_POST['coll'];
$events = array();

$events=$_POST['events'];

$ev2=implode(',', $events);
$_SESSION["eventsname"]=$ev2;
$key = uniqid();
$_SESSION["unique"] = "$key";
$q1 = $_POST['q1'];
if(empty($q1)){
$q1="abc";
}
if($college2!=='Others')
{
$college=$_POST['coll'];
$course=$_POST['course'];
}
else{
$college=$_POST['college'];
$course="null";
}
if ($q1!== "abc")
{

$select = mysqli_query($link, "SELECT `email` FROM `person2` WHERE `email` = '$email'") or exit(mysqli_error($link));
if(mysqli_num_rows($select)) {
header('location: err.php');
exit('This email is already being used');
}

$sql = "INSERT INTO person2 (name, email, mobile, college, course, events, entry, unkey) VALUES ('$name','$email','$mobile','$college','$course', '$ev2', '$q1', '$key')";
if(mysqli_query($link, $sql)){

} else{

}   
}else
{
 $select = mysqli_query($link, "SELECT `email` FROM `person3` WHERE `email` = '$email'") or exit(mysqli_error($link));
if(mysqli_num_rows($select)) {
header('location: err.php');
exit('This email is already being used');
}
$sql = "INSERT INTO person3 (name, email, mobile, college, course, unkey) VALUES ('$name', '$email','$mobile','$college','$course','$key')";
if(mysqli_query($link, $sql)){

} else{

}   
}
// Close connection
mysqli_close($link);
?>

2 个答案:

答案 0 :(得分:0)

嗨,尝试在您的选项中设置一个值(选择)

答案 1 :(得分:0)

您必须按如下所示为所有标签赋予值。

例如

console.log(all_operational.flat())

编辑:-从“事件”数组中跳过空/空值。

<select class="form-control" id="indi" name="events[]" multiple required>
    <option value="Solo Singing">Solo Singing</option>
    <option value="Solo Dance">Solo Dance</option>
    <option value="Beat Boxing">Beat Boxing</option>
    <option value="Mono Acting">Mono Acting</option>
    <option value="Photography">Photography</option> 
    <option value="Just a minute">Just a minute</option>  
</select>