使用JQuery添加无限表单字段并保存到具有多行的数据库

时间:2016-12-30 09:34:34

标签: javascript php jquery mysql html5

$rs1=mysql_query("SELECT * FROM companydetails ORDER BY companyname");    
$customerlist="<option value=''></option>";
while($row=mysql_fetch_array($rs1))
{        
    $customerlist.="<OPTION VALUE=".$row["comid"]." >";
    $customerlist.=$row["companyname"]."</OPTION>";        
}

$query_parent = mysql_query("SELECT * FROM `material` order by `marterial_name`") or die("Query failed: ".mysql_error());
$material='<option value=""></option>';
while($row = mysql_fetch_array($query_parent))
{   
    $material.="<option value=" .$row["id"].">";
    $material.=$row["marterial_name"]."</option>";
}                                                                                                                                      
$query_parent1 = mysql_query("SELECT * FROM `material_location` order by `location`") or die("Query failed: ".mysql_error());

$exclusivetax=mysql_query("SELECT * FROM exclusive_tax ORDER BY id");    
$tax='<option value=""></option>';
while($row=mysql_fetch_array($exclusivetax))
{                
    $tax.="<OPTION VALUE=".$row["id"]." >";
    $tax.=$row["tax"]."</OPTION>";
}

$rs1=mysql_query("SELECT * FROM quotation_type ORDER BY type");    
$purchase_type='<option value=""></option>';
while($row=mysql_fetch_array($rs1))
{                
    $purchase_type.="<OPTION VALUE=".$row["id"]." >";
    $purchase_type.=$row["type"]."</OPTION>";
}    

$rs1=mysql_query("SELECT * FROM cz where (role='purchase' or role='sales' or role='Repair' or role='admin' or role='CSM' or role='Teamleader' or role='Superuser') and status='Active' order by username");
$u="<OPTION VALUE=''></OPTION>";
while($row=mysql_fetch_array($rs1))
{
    $u.="<OPTION VALUE=".$row["email2"]." >";
    $u.=$row["email2"]."</OPTION>";
    //$email2=$row["email2"];
}    

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Cp1252">
<script language="javascript" src="../calendar/calendar.js"></script>
<link href="../calendar/calendar.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
        SyntaxHighlighter.all();
</script>
<script type="text/javascript" src="../js/custombox.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="../js/jquery.searchabledropdown-1.0.8.min.js"></script>
<script type="text/javascript">
 var $old = $.noConflict();
</script>
<link rel="stylesheet" href="../css/custombox.css">
<script type="text/javascript">

$(document).ready(function() {

    $("#parent_cat").change(function() {
        $me=$(this).val();
        $.get('loadsubcat.php?parent_cat=' + $(this).val(), function(data) {
            $("#sub_cat").html(data);    
        });    
    });
});
</script>
<script type="text/javascript">
$(document).ready(function() {

    $.get('pdetail.php', function(data) {
        $("#users").html(data);    
        });

    $("#category").change(function() {
        $me=$(this).val();
        $.get('pdetail.php?category=' + $me, function(data) {
            $("#users").html(data);    
            });

        });        
});
</script>

<script type="text/javascript">
$(document).ready(function() {

    $("#parent_cat").change(function() {
        $me=$(this).val();

    });
        $("#sub_cat").change(function() {
            $me1=$(this).val();

            $.get('material_type.php?parent_cat=' + $me + '& sub_cat=' + $me1 , function(data) {
                $("#sub_cat11").html(data);
        });    
    });

});
</script>
<script type="text/javascript">

$(document).ready(function() {

    $("#parent_cat").change(function() {
        $me=$(this).val();
        });
    $("#sub_cat").change(function() {
        $me1=$(this).val();
        });       

        });    
    });    
    $(function () {
        $('#stock').on('click', function ( e ) {
            Custombox.open({
                target: 'view_stock_full_detail.php?id=1& material=' + $me + '& maker='+ $me1 +'& type=' + $me2,
                effect: 'fadein',
                escKey: true,
                overlaySpeed: 100,
                overlayClose: true,
                speed: 100
            });
            e.preventDefault();
        });
    });        
});

</script> 
<script type="text/javascript">
    $(document).ready(function ($) 
    {
        //initilize any plugins that need the newer version of jquery
        var counter = 2;

           $("#addButton").click(function () 
           {                
            if(counter>10)
            {
                alert("You can add only 10 Material Details");
                return false;
            }   
            var newTextBoxDiv = $(document.createElement('div'))
             .attr("id", 'TextBoxDiv' + counter)
             .attr("style",'margin-top:10px;margin-left:2px;');
            newTextBoxDiv.after().html( '<table border="1px" BORDERCOLOR="#98AFC7">'+
                                            '<tr>'+
                                                '<td width="100px">'+
                                                     '<div  style="width:150;height:20px; float:left; text-align:center">'+
                                                         '<font size="+1">Material:</font>'+
                                                     '</div>'+
                                                 '</td>'+
                                                 '<td width="200px">'+
                                                      '<div style="float:left;margin-left:20px;">'+
                                                           '<select class="nav" name="parent_cat1[]" id="parent_cat' + counter + '"> <?php echo $material; ?> </select>'+
                                                       '</div>'+
                                                 '</td>'+
                                                 '<td width="100">'+
                                                      '<div  style="width:100;height:20px; text-align:center">'+
                                                           '<font size="+1">Make:</font>'+
                                                      '</div>'+
                                                 '</td>'+
                                                 '<td>'+
                                                      '<div style="float:left;margin-left:20px;">'+
                                                          '<select class="nav" name="sub_cat1[]" id="sub_cat'+ counter +'"></select>'+
                                                      '</div>'+
                                                 '</td>'+
                                            '</tr>'+
                                        '</table>'+
                                        '<table border="1px" BORDERCOLOR="#98AFC7">'+
                                             '<tr>'+
                                                 '<td width="100">'+
                                                     '<div style="width:150;height:20px; float:left; text-align:center">'+
                                                          '<font size="+1">Type:</font>'+
                                                     '</div>'+
                                                 '</td>'+
                                                 '<td>'+ 
                                                     '<div style="float:left;margin-left:20px;">'+
                                                          '<select class="nav" name="sub_cat111[]" id="sub_cat11'+ counter +'"></select>'+
                                                     '</div>'+
                                                 '</td>'+
                                                 '<td>'+
                                                     '<div style="width:100px;height:20px;text-align:center">'+
                                                         '<font size="+1">Quantity:</font>'+
                                                     '</div>'+
                                                 '</td>'+
                                                 '<td>'+
                                                     '<div  style="margin-left:20px;">'+
                                                         '<input type="text" name="quantity1[]" id="quantity">'+
                                                     '</div>'+
                                                 '</td>'+
                                                 '<td>'+
                                                     '<div  id="stock' + counter +'" name="stock" style="width:150px;height:20px;text-align:center; margin-left:20px;"></div>'+
                                                 '</td>'+
                                             '</tr>'+
                                             '<tr>'+


                                                 '<td>'+
                                                     '<div style="width:100px;height:20px;text-align:center">'+
                                                         '<font size="+1">Sales Detail:</font>'+
                                                     '</div>'+
                                                 '</td>'+
                                                 '<td>'+
                                                     '<div  style="margin-left:20px;">'+
                                                         '<textarea rows="2" cols="25" name="s_price1[]" id="s_price" ></textarea>'+
                                                     '</div>'+
                                                 '</td>'+
                                                 '<td>'+
                                                    '<div style="margin-left:20px;width:100px;">'+
                                                        '<input type="checkbox" name="s_including1[]" id="including" value="including"><font size="+0">Including</font>'+
                                                        '<input type="checkbox" name="s_including1[]" id="excluding" value="excluding"><font size="+0">Excluding</font>'+
                                                        '<select class="nav" name="s_excluding_tax1[]" id="p_excluding_tax' + counter + '"> <?php echo $tax; ?> </select>'+
                                                    '</div>'+

                                                    '<td>'+
                                                     '<div style="width:100px;height:20px;text-align:center">'+
                                                         '<font size="+1">Price:</font>'+
                                                     '</div>'+
                                                 '</td>'+
                                                 '<td>'+
                                                     '<div  style="margin-left:20px;">'+
                                                         '<input type="text" name="price1[]" id="price">'+
                                                     '</div>'+
                                                 '</td>'+

                                                '</td>'+
                                             '</tr>'+
                                         '</table>');
            newTextBoxDiv.appendTo("#TextBoxesGroup");
            var i=counter;

            $("#parent_cat" + counter ).change(function() {
                $me=$(this).val();

                $.get('loadsubcat.php?parent_cat=' + $me, function(data) {

                    $("#sub_cat" + i  ).html(data);
                });    
            });
            $("#parent_cat" + counter ).change(function() {
                $me=$(this).val();

            });
                $("#sub_cat" + i ).change(function() {
                    $me1=$(this).val();

                    $.get('material_type.php?parent_cat=' + $me + '& sub_cat=' + $me1 , function(data) {
                        $("#sub_cat11" + i ).html(data);
                });    
            });
            $("#sub_cat" + i).change(function() {
                    $me1=$(this).val();
            });
                $("#sub_cat11" + i).change(function() {
                    $me2=$(this).val();
                    $.get('stock_value5.php?parent_cat=' + $me + '& sub_cat=' + $me1 + '& sub_cat11=' + $(this).val() , function(data) {
                        $("#stock" + i).html(data);

                    });    
                });                    
            counter++;                
         });

         $("#removeButton").click(function () 
         {
            if(counter==2)
            {
                alert("No more Material Details to remove");
                return false;
               }   
            counter--;
            $("#TextBoxDiv" + counter).remove();
         });
         $("#save").click(function () 
         {
            var msg = '';
            for(i=1; i<counter; i++)
            {
                     msg += $('#person' + i).val();
            }  
         });

    });

    $old(document).ready(function ($) {
        //initilize any plugins that need the older version of jquery
        $("#select").searchable();
    });
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script>
function openWin()
{
    var myWindow = window.open("new_material.php","","width=300,height=200");
}
function openWin1()
{
    var myWindow = window.open("new_make.php","","width=300,height=200");
}

function openWin4()
{
    var myWindow = window.open("new_material_type.php","","width=300,height=200");
}
function stopRKey(evt) { 
      var evt = (evt) ? evt : ((event) ? event : null); 
      var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
      if ((evt.keyCode == 13) && (node.type=="text"))  {return false;} 
    } 

    document.onkeypress = stopRKey; 
</script>

<title>Solution Infinite</title>
<style type="text/css">
font
{
    color:#FFFFFF
}
</style>

</head>

    <body>
    <form action="pdsave.php" method="post" name="quatation" id="quatation" >
    <input type="hidden" name="form_secret" value="<?php echo $_SESSION['FORM_SECRET'] ?>" />
    <div align="center"><font color="#FFFFFF" size="+1"><b>Quotation Form</b></font></div>
    <div class='ex'>
    <table  style="margin-top:15px;">
        <tr>
            <td>
                <div  style="width:150;height:20px; float:left; text-align:center">
                    <font size="+1">Date:</font>
                 </div>
            </td>
            <td>
                <div style="float:left;margin-left:20px; width:250px;">
                     <?php                          
                           $fdate_default =$date;    
                           $todate_default =$date;
                           $myCalendar = new tc_calendar("fdate", true, false);     
                        $myCalendar->setIcon("../calendar/images/iconCalendar.gif");      
                        $myCalendar->setDate(date('d', strtotime($fdate_default))
                        , date('m', strtotime($fdate_default))
                        , date('Y', strtotime($fdate_default)));      
                        $myCalendar->setPath("../calendar/");     
                         $myCalendar->setYearInterval(1970, 2020);    
                           $myCalendar->setAlignment('left', 'bottom');        
                        $myCalendar->writeScript();    
                        $time=date("H:i:s");
                    ?>   
                <input type="hidden" name="time" value="<?php echo $time?>">
                 </div>
            </td>
            <td>
                <div  style="width:200;height:20px; float:left; text-align:center">
                    <font size="+1">Delivery Expected Date:</font>
                 </div>
            </td>
            <td>
                <div style="float:left;margin-left:20px; width:250px;">
                     <?php                          
                           $myCalendar = new tc_calendar("todate", true, false);     
                        $myCalendar->setIcon("../calendar/images/iconCalendar.gif");      
                        $myCalendar->setDate(date('d', strtotime($todate_default))
                        , date('m', strtotime($todate_default))
                        , date('Y', strtotime($todate_default)));      
                        $myCalendar->setPath("../calendar/");     
                         $myCalendar->setYearInterval(1970, 2020);    
                           $myCalendar->setAlignment('left', 'bottom');        
                        $myCalendar->writeScript();    
                        $time=date("H:i:s");
                    ?>   
                <input type="text" name="expected_time" value="<?php echo $time?>">
                 </div>
            </td>
        </tr>
    </table>          

    <div id='TextBoxesGroup'>
        <table border='1px' BORDERCOLOR='#98AFC7' style="margin-top:15px;">
        <div id="TextBoxDiv1">
            <tr>
                <td>
                    <div style="width:150;height:20px; float:left; text-align:center">
                        <font size="+1">Material:</font>
                     </div>
                </td>
                <td>
                    <div style="float:left;margin-left:20px;">
                        <select class="nav" name="parent_cat" id="parent_cat">
                            <?php echo $material;?>
                           </select> 
                    </div>
                </td>
                <td>
                    <input class="button1 black" type="button" value="new" onClick=      "openWin()">
                </td>
                <td>
                    <div style="width:75;height:20px; float:left; text-align:center">
                        <font size="+1">Make:</font>
                     </div>
                </td>
                   <td>
                    <div style="float:left;margin-left:20px;">
                        <select class="nav" name="sub_cat" id="sub_cat"></select>
                    </div>
                </td>
                <td>                     
                        <input type="button" class="button1 black" value="new" onClick="openWin1()">                       
                </td>
                <td>
                    <div style="margin-left:20px;">
                        <input type='button' value='Add' id='addButton' style="width:auto" >
                    </div>
                </td>
                <td><input type='button' value='Remove' id='removeButton' style="width:auto" ></td>
            </tr>
        </table>
        <table border='1px' BORDERCOLOR='#98AFC7'>
            <tr>
                <td>
                    <div  style="width:150;height:20px; float:left; text-align:center">
                        <font size="+1">Type:</font>
                     </div>
                </td>
                   <td>
                    <div style="margin-left:20px;">
                        <select class="nav" name="sub_cat11" id="sub_cat11"></select>
                    </div>
                </td>
                <td>                     
                    <input type="button" class="button1 black" value="new" onClick="openWin4()">                   
                </td>
                <td>
                    <div  style="width:150;height:20px; float:left; text-align:center">
                        <font size="+1">Quantity:</font>
                    </div>
                </td>
                <td>
                    <div  style="margin-left:20px; float:left;">        
                        <input type="text" name="quantity" id="quantity">
                    </div>
                </td>
                <td>
                    <div  id="stock" name="stock" style="width:150px;height:20px; float:left;text-align:center; margin-left:10px;">        
                    </div>
                </td>

            </tr>
            <tr>

                <td>
                    <div  style="width:100px;height:20px; margin-left:20px; text-align:center">
                        <font size="+1">Sales Detail:</font>
                    </div>
                </td>
                <td>
                    <div style="float:left;margin-left:20px;">
                        <textarea rows="2" cols="25" name="s_price" id="s_price"></textarea>
                    </div>
                </td>
                <td>
                    <div style="float:left;margin-left:20px;width:100px;">
                        <input type="checkbox" name="s_including" id="including" value="including"><font size="+0">Including</font>
                        <input type="checkbox" name="s_including" id="excluding" value="excluding"><font size="+0">Excluding</font>
                        <select name="s_excluding_tax" id="s_excluding_tax" class="nav">
                            <?php echo $tax;?>
                        </select>
                    </div>
                </td>                   
            </tr>
        </div>
        </table>
    </div>

    <table align="center">
    <tr>
    <td>
        <input type="submit" value="submit" name="submit" class="button1 blue"  />
    </td>
    <td>
        <input class="button1 blue" type="reset" value="Clear">
    </td>
    <td>
        <input  TYPE="Button" value="Close"  class="button1 blue" onClick="javascript:location.href=('dashboard.php');">
    </td>
    </tr>
    </table>
   </div>
    </form>
    </body>
</html> 

这是我的html页面我要插入多个列值并插入到数据库中是完全但是所有材料和制造商值都插入到单列但我想在不同的列中插入值所有product1,2,3等如果我选择三个不同列中3个材料的3倍是可能的,因为我是php的新手并没有得到正确的解决方案 这是我的PHP代码

0 个答案:

没有答案