多项选择不会发布所选的ID

时间:2014-03-12 09:32:11

标签: javascript php jquery

我有一个选项面板,您可以在其中选择多个变量。但是当我选择一个变量时,它不会在数据库中发布id。

html表格:

<form class="form-inline">
<div id="d1" title="Nieuwe afspraak" style="display: none">
<label class="control-label">Werknemer(s):</label>
<select name="werknemer[]" data-placeholder="werknemer..." id="werknemer" multiple="multiple" class="chzn-select"  style="width:300px;" tabindex="4">                   
                    <option value=""></option> 
                <?if($werknemers !=null):foreach($werknemers as $row):?>
                    <option value='<?=$row->idWerknemer;?>'><?=$row->Voornaam;?>&nbsp;(<?=$row->Achternaam;?>)</option> 
                <?endforeach;endif;?>
            </select><br />
            <div class="control-group">
                <label class="control-label">Titel:</label>
            <div class="controls">
                <input type="text" name="username" placeholder="Titel" id="name"/>*
            </div>
        </div>
        <div class="control-group">
                <label class="control-label">Omschrijving:</label>
            <div class="controls">
                <input type="text" name="userdesc" placeholder="Beschrijving" id="desc"/>*
            </div>
        </div>
        <button style="float:right; margin-right:34px;" onclick="toggle_div_fun('sectiontohide');">Geavanceerd</button>
        <div id="sectiontohide" style="display:none;">
        <div class="control-group" >
        <label class="control-label">Project:</label>
        <div class="controls">
        <select onChange='$("#klant").val("NULL");$("#klant").trigger("liszt:updated");' name="project" data-placeholder="Project..." class="chzn-select" id="project" style="width:160px;" tabindex="4">
        <option value="NULL"></option> 
        <?if($projecten_titel !=null):foreach($projecten_titel as $row):?>
        <option value='<?=$row->idProject;?>'><?=$row->Titel;?> (<?=$row->Naam;?>)</option> 
        <?endforeach;endif;?>
        </select><br /><br /></div>
         </div><div class="control-group" >
        <label class="control-label">Klant:</label>
        <div class="controls">
        <select  onChange='$("#project").val("NULL");$("#taak").val("NULL");$("#project").trigger("liszt:updated");$("#taak").trigger("liszt:updated");' name="klant" data-placeholder="Klant..." class="chzn-select" id="klant" style="width:160px;" tabindex="4">
        <option value="NULL"></option> 
        <?if($klanten !=null):foreach($klanten as $row):?>
        <option value='<?=$row->idKlant;?>'><?=$row->Naam;?></option> 
        <?endforeach;endif;?>
        </select><br /><br /></div>
         </div><div class="control-group" >
        <label class="control-label">Taak:</label>
        <div class="controls">
        <select  onChange='$("#klant").val("NULL");$("#klant").trigger("liszt:updated");' name="taak" data-placeholder="Klant..." class="chzn-select" id="taak" style="width:160px;" tabindex="4">
        <option value="NULL"></option> 
        <?if($taken !=null):foreach($taken as $row):?>
        <option value='<?=$row->idTaak;?>'><?=$row->Titel1;?></option> 
        <?endforeach;endif;?>
        </select><br /><br /></div>
         </div>
         </div>

            <div class="control-group">
                <label class="control-label">Van:</label>
            <div class="controls">
                <input type="startdate" name="userstart" placeholder="Starttijd" id="start"/>*
                <input type="time" name="mytime" value="00:00:00" placeholder="starttime" id="starttime"/>
            </div>
        </div>
        <div class="control-group">
                <label class="control-label">Tot:</label>
            <div class="controls">          
                <input type="einddate" name="userend" placeholder="Eindtijd" id="end"/>*
                <input type="time" name="mytime" value="00:00:00" placeholder="endtime" id="endtime"/>
            </div>  
</div>
    <div class="control-group">
                <label class="control-label">Color:</label>
            <div class="controls">      
<select name="color[]" id="colorstatus" data-placeholder="colors..." class="chzn-select" tabindex="4">

                <?if($colors !=null):foreach($colors as $row):?>
                    <option value='<?=$row->colortag;?>'><?=$row->soort;?></option> 
                <?endforeach;endif;?>
            </select><br />
            </div>  
</div></div>
<div id="d2" title="Checking Empty..." style="display:none;">
    <p>Vul alstublieft wat in....!</p>
</div>
</div>

nieuwe afspraak.js:

$(function () {
// Dialog Open   
$("#d1").dialog({
    autoOpen: false,
    height: 'auto',
    width: 'auto',
    modal: true,
    closeOnEscape:true, 
    resizable:false, 
    show:'fade',
    buttons: { 
      "Add": function() { 

        var id = $("#id").val(),
        werknemer = $('#werknemer').val(),
        project = $('#project').val(),
        klant = $('#klant').val(),
        taak = $('#taak').val(),
        name = $('#name').val(),
        desc = $('#desc').val(),
        start = $('#start').val(),
        starttime = $('#starttime').val(),
        end = $('#end').val(),
        endtime = $('#endtime').val();
        colorstatus = $('#colorstatus').val();

        if(id=='' || werknemer=='' || name=='' || desc=='' || start=='' || end=='')
            {
                //alert("Please do not empty....!",title="Hello");
                $("#d2").dialog("open");
                $("#d2").dialog({
                    buttons:{
                        "OK":function(){
                                $(this).dialog("close");
                                $("#id:first").focus(); 
                            }
                        }
                    }); 
                exit;
            }//End if statement

        $.post('../testcalendar/db/process.php',{
            user_id: id, user_werknemer: werknemer, user_project: project, user_klant: klant,user_taak: taak, user_name: name, user_desc: desc, user_start: start, user_starttime: starttime, user_end: end, user_endtime: endtime, user_color: colorstatus, action:'joined'
        }); var nTime = 1 * 50;

        window.setTimeout("location.reload()", nTime);//End Post
        $("#id").val('');
        $("#werknemer").val('');
        $("#project").val('');
        $("#klant").val('');
        $("#taak").val('');
        $("#name").val('');
        $("#desc").val('');
        $("#start").val('');    
        $("#starttime").val('');
        $("#end").val('');  
        $("#endtime").val('');          
        $("#colorstatus").val('');          
        $(this).dialog("close");        
        },
      "Cancel": function() { 
        $("#id").val('');
        $("#werknemer").val('');
        $("#project").val('');
        $("#klant").val('');
        $("#taak").val('');
        $("#name").val('');
        $("#desc").val('');
        $("#start").val('');
        $("#starttime").val('');
        $("#end").val('');
        $("#endtime").val('');  
        $("#colorstatus").val('');  
        $(this).dialog("close"); 
        } 
    }
});


$("#d2").dialog({
    autoOpen: false,
    height: 'auto',
    width: 'auto',
    modal: true,
    closeOnEscape:true, 
    resizable:false, 
    show:'fade',
    buttons: { 
      "Ok": function() { $(this).dialog("close"); } 
    }
});

$("#b1").click(function(){
    $("#d1").dialog("open");
});
$("#start").datepicker({ dateFormat: 'yy-mm-dd' });
$("#end").datepicker({ dateFormat: 'yy-mm-dd' });
$('input[type="time"] ').timepicker();
});

function showDiv() {
   document.getElementById('welcomeDiv').style.display = "block";
}

process.php:         

        $q = "INSERT INTO evenement (id,idWerknemer,idProject,idKlant,idTaak,title,description,start,end,color) VALUES 
            ('','".$user_werknemer."','".$user_project."','".$user_klant."','".$user_taak."','".$user_name."','".$user_desc."','".$user_start."','".$user_end."','".$user_color."')";
        $qo = "INSERT INTO evenementontvanger (idWerknemer,idProject,idEvent,idKlant,idTaak) VALUES ('".$user_werknemer."','".$user_project."','','".$user_klant."','".$user_taak."')";
 foreach ($user_werknemer as $werknemer){

    mysql_query($q);
    mysql_query($qo);
    }}


if(isset($_POST['user_werknemer'],$_POST['user_project'],$_POST['user_klant'],$_POST['user_taak'],$_POST['user_name'],$_POST['user_desc'],$_POST['user_start'],$_POST['user_starttime'],$_POST['user_endtime'],$_POST['user_end'],$_POST['user_color'],$_POST['action'])){
        $user_werknemer=$_POST['user_werknemer'];
        $user_color=$_POST['user_color'];
        $user_name=$_POST['user_name'];
        $user_desc=$_POST['user_desc'];
        $user_project=$_POST['user_project'];
        $user_klant=$_POST['user_klant'];
        $user_taak=$_POST['user_taak'];
        $user_start=$_POST['user_start']." ".$_POST['user_starttime'];
        $user_end=$_POST['user_end']." ".$_POST['user_endtime'];
        $action=$_POST['action'];
        if ($action=='joined'){
            user_joined( $user_werknemer, $user_project, $user_klant, $user_taak, $user_name, $user_desc, $user_start, $user_end, $user_color);
            }
    } ?>

我认为foreach循环不会以某种方式获取每个“user_werknemer”的id。

1 个答案:

答案 0 :(得分:0)

看起来您的查询变量位于错误的位置。此外,你在循环后有一个额外的}。

foreach ($user_werknemer as $werknemer){


        $q = "INSERT INTO evenement (id,idWerknemer,idProject,idKlant,idTaak,title,description,start,end,color) VALUES 
            ('','".$user_werknemer."','".$user_project."','".$user_klant."','".$user_taak."','".$user_name."','".$user_desc."','".$user_start."','".$user_end."','".$user_color."')";
        $qo = "INSERT INTO evenementontvanger (idWerknemer,idProject,idEvent,idKlant,idTaak) VALUES ('".$user_werknemer."','".$user_project."','','".$user_klant."','".$user_taak."')";

    // for debugging only
    print ("q = $q <br /> qo = $qo <br /><br />");
    ///////////////


    mysql_query($q);
    mysql_query($qo);
    }