我有下列复选框

<input type="checkbox" name="weekday[]" value="Monday" /> Monday &nbsp;&nbsp;&nbsp;
<input type="checkbox" name="weekday[]" value="Tuesday" /> Tuesday &nbsp;&nbsp;&nbsp;
<input type="checkbox" name="weekday[]" value="Wednesday" /> Wednesday </br>
<input type="checkbox" name="weekday[]" value="Thursday" /> Thursday &nbsp;&nbsp;&nbsp;
<input type="checkbox" name="weekday[]" value="Friday" /> Friday &nbsp;&nbsp;&nbsp;
<input type="checkbox" name="weekday[]" value="Saturday" /> Saturday &nbsp;&nbsp;&nbsp;
<input type="checkbox" name="weekday[]" value="Sunday" /> Sunday &nbsp;&nbsp;&nbsp;

我想在mysql的“day”字段中输入所有被coma分隔的检查值,
请帮忙

最佳答案

   if(isset($_POST['submit_btn_name']))
   {
      $days="";

      if(isset($_POST['weekday']))
      {

          foreach($_POST['weekday'] as $id)
          {
                $days.=$id.",";
          }
              $days = substr($days, 0, -1);

      }

      echo $days;

   }

编辑
这是对有关发布$days变量的查询的注释的响应,因为我发现很难在注释中格式化代码。
  $sql1=mysql_query("INSERT INTO class (class_id, subject_id, student_id, available_days, available_time, status) VALUES ('".$class_id."','".$subject_id."','".$student_id."','".$days."','".$available_t‌​ime."','pending')"‌​)or die('Error: There was error while submitting the schedule, please try again.');

10-08 07:17