Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > PHP > PHP Forum > ขอความช่วยเหลือครับ จะต้องเขียน code ที่ถูกต้องเพื่อที่จะ insert รายการของ cell1.innerHTML ไปฐานข้อมูลอย่างไรครับ


[PHP] ขอความช่วยเหลือครับ จะต้องเขียน code ที่ถูกต้องเพื่อที่จะ insert รายการของ cell1.innerHTML ไปฐานข้อมูลอย่างไรครับ

 
Topic : 126079



โพสกระทู้ ( 111 )
บทความ ( 0 )



สถานะออฟไลน์



ต้องขอโทษที่ต้องยก Code มาทั้งหมด(ยาวหน่อยครับ)


repair_input.php


<Code (PHP)
001.!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
002.<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" >
003.<head>
004.  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
005.  <script type="text/javascript" src="../jQueryui/jQuery.js"></script>
006.  <script type="text/javascript" src="../jQueryui/jQuery-ui.js"></script>
007. 
008.</head>   
009.     
010.<form action="insertData.php" method="post" name="adminForm" id="adminForm">
011.  <table class="adminlist">
012.    <thead>
013.      <tr>
014.        <th ><div class="titleleft"> เพิ่มรายการซ่อม </div>
015.          <div class="titleright"> <a href="#" onclick="document.adminForm.task.value=''; document.adminForm.submit();">
016.            <div id="icon">
017.              <div class="icon-32-cancel"></div>
018.              <div class="title">ยกเลิก</div>
019.            </div>
020.            </a> <a href="#" onclick="save();">
021.            <div id="icon">
022.              <div class="icons-32-save"></div>
023.              <div class="title">บันทึก</div>
024.            </div>
025.            </a> </div></th>
026.      </tr>
027.    </thead>
028.  </table>
029.  <fieldset class="adminform">
030.    <legend>ข้อมูลเบื้องต้น</legend>
031.  </fieldset>
032.   
033.   
034.   
035.  <fieldset class="adminform">
036.    <legend>รายละเอียดการซ่อม</legend>
037.     
038.  <table class="adminlist">
039.    <thead>
040.      <tr>
041.        <th width="90" >วันที่</th>
042.        <th width="61" >รหัส</th>
043.        <th width="87" >เลขใบเสร็จ</th>
044.        <th width="87" >รหัสอะไหล่</th>
045.        <th width="157">รายละเอียดการซ่อม</th>
046.        <th width="37" >จำนวน</th>
047.        <th width="47" >หน่วยละ</th>
048.        <th width="47" >ลด</th>
049.        <th width="47" >ยอดรวม</th>
050.        <th width="87" >ผู้ตรวจรับรถ</th>
051.        <th width="87" >สถานที่เข้าซ่อม</th>
052.        <th></th>
053.      </tr>
054.    </thead>
055.      <tbody id="repairlist">
056.      <tr>
057.         <td colspan="12">ยังไม่มีรายการใหม่ เพิ่มรายการใหม่ด้านล่าง</td>
058.      </tr>
059.      </tbody>
060.      <tr>
061.        <th width="90" >วันที่</th>
062.        <th width="61" >รหัส</th>
063.        <th width="87" >เลขใบเสร็จ</th>
064.        <th width="87" >รหัสอะไหล่</th>
065.        <th width="157">รายละเอียดการซ่อม</th>
066.        <th width="37" >จำนวน</th>
067.        <th width="47" >หน่วยละ</th>
068.        <th width="47" >ลด</th>
069.        <th width="47" >ยอดรวม</th>
070.        <th width="87" >ผู้ตรวจรับรถ</th>
071.        <th width="87" >สถานที่เข้าซ่อม</th>
072.        <th></th>
073.      </tr>
074.    <tr>
075.      <td><input type="text" name="date_repair" id="datepicker" value="" class="inputbox" size="25" maxlength="19" style="width:65px !important;" />
076.        <img src="../image/calendar.png" width="16" height="16" alt="logo" longdesc="calendar.png" /></td>
077.      <td><select name="rid" id="rid" style="width:60px !important;" class="inputbox" size="1"  ><option value="0"  selected="selected">R-ID</option><option value="7" >เครื่องยนต์</option><option value="8" >ห้องเครื่อง</option><option value="9" >ระบบแอร์</option><option value="10" >ระบบไฟฟ้า</option><option value="11" >เบรค-ยาง-ล้อ</option><option value="12" >ช่วงล่าง</option><option value="13" >เกียร์เ-ฟืองท้าย</option><option value="14" >ภายใน</option><option value="16" >อุปกรณ์</option><option value="17" >ความสะอาด</option><option value="18" >เช็คระยะ-ระบบ</option><option value="19" >เคลม Warranty</option><option value="20" >เคลมประกันทำสีรถ</option></select></td>
078.      <td><input class="text_area" type="text" name="repair_number" id="repair_number" size="32" maxlength="250" style="width:80px !important;"  /></td>
079.      <td><input class="text_area" type="text" name="part_number" id="part_number" size="32" maxlength="250" style="width:80px !important;"  /></td>
080.      <td><input class="text_area" type="text" name="repair_detail" id="repair_detail" size="32" maxlength="250" style="width:150px !important;"  /></td>
081.      <td><input class="text_area" type="text" name="amount" id="amount" size="32" maxlength="250" style="width:30px !important;"  /></td>
082.      <td><input class="text_area" type="text" name="price_perunit" id="price_perunit" size="32" maxlength="250" style="width:40px !important;"  /></td>
083.      <td><input class="text_area" type="text" name="price_discount" id="price_discount" size="32" maxlength="250" style="width:40px !important;" onchange="caldiscount();"  /></td>
084.      <td><input class="text_area" type="text" name="price_total" id="price_total" size="32" maxlength="250" style="width:40px !important;"  /></td>
085.      <td><input class="text_area" type="text" name="recive_by" id="recive_by" size="32" maxlength="250" style="width:80px !important;"  /></td>
086.      <td><input class="text_area" type="text" name="repair_at" id="repair_at" size="32" maxlength="250" style="width:80px !important;"  /></td>
087.      <td></td>
088.    </tr>
089.    <tr>
090.        <th >เลขไมล์</th>
091.         <td ><input class="text_area" type="text" name="mile" id="mile" size="32" maxlength="10"  style="width:50px !important;" /></td>
092.        <th >หมายเหตุ</th>
093.         <td colspan="6"><input class="text_area" type="text" name="repair_remark" id="repair_remark" size="32" maxlength="250"  style="width:450px !important;" /></td>
094.         <td colspan="3"><input name="" type="button" value="เพิ่มลงในรายการ" onclick="addlist();" /></td>
095.      </tr>
096.  </table>
097.    </fieldset>
098.  <fieldset class="adminform">
099.  <table width="100%" border="0" cellspacing="1" cellpadding="0">
100.   
101.</table>
102. 
103.  </fieldset>
104.  <input type="hidden" name="Itemid" value="35" />
105.  <input type="hidden" name="option" value="com_car" />
106.  <input type="hidden" name="task" value="" />
107.  <input type="hidden" name="step" value="1" />
108.<input type="hidden" name="c777fc3101862d44330268006e1e1480" value="1" />  <input type="hidden" name="view" value="repairadd" />
109.</form>
110.<script language="javascript">
111.var indexlist = 0;
112.function caldiscount(){
113.        var form = document.getElementById('adminForm');
114.           var check = true;
115.          var value =form.price_discount.value; //get characters
116.          var perc = false;
117.          //check that all characters are digits, ., -, or ""
118.          for(var i=0;i <value.length; ++i)
119.          {
120.               var new_key = value.charAt(i); //cycle through characters
121.               if(((new_key < "0") || (new_key > "9")) &&
122.                    !(new_key == ""))
123.               {
124.                   if(new_key != "%"){
125.                    check = false;
126.                    break;
127.                   }else{
128.                     perc = true; 
129.                   }
130.               }
131.          }
132.        if(!check){
133.            alert("ตัวเลขเท่านั้น เช่น 300 หรือ 10%");
134.            form.price_discount.value = "";
135.            form.price_discount.focus();
136.        //  price_perunit
137.        //  price_total
138.        }else{
139.            if(perc){
140.                value = value.substr(0,value.length-1);
141.                value = parseInt(value,10);
142.                value =  (parseInt(form.price_perunit.value,10)*parseInt(form.amount.value,10))*(value/100);
143.            }
144.                form.price_total.value = (parseInt(form.price_perunit.value,10)*parseInt(form.amount.value,10))-value;
145.        }
146.}
147.function addlist(){
148.        var form = document.getElementById('adminForm');
149.    if(form.rid.selectedIndex == 0){
150.        alert("เลือกรหัสการซ่อม");
151.    }else{
152.        var tr = document.getElementById('repairlist');
153.         
154.        var rcount = tr.rows.length;
155.        if(rcount == 1){
156.            tr.deleteRow(0);
157.        }
158.         
159.         
160.        rcount = tr.rows.length;
161.        var row = tr.insertRow(rcount);
162.        row.setAttribute("id","rows"+indexlist);
163.        var cell1 = row.insertCell(0);
164.        cell1.innerHTML = form.date_repair.value;
165.        var cell1 = row.insertCell(1);
166.        cell1.innerHTML =  form.rid[form.rid.selectedIndex].text;
167.        var cell1 = row.insertCell(2);
168.        cell1.innerHTML = form.repair_number.value;
169.        var cell1 = row.insertCell(3);
170.        cell1.innerHTML = form.part_number.value;
171.        var cell1 = row.insertCell(4);
172.        cell1.innerHTML = form.repair_detail.value;
173.        var cell1 = row.insertCell(5);
174.        cell1.innerHTML = form.amount.value;
175.        var cell1 = row.insertCell(6);
176.        cell1.innerHTML = form.price_perunit.value;
177.        var cell1 = row.insertCell(7);
178.        cell1.innerHTML = form.price_discount.value;
179.        var cell1 = row.insertCell(8);
180.        cell1.innerHTML = form.price_total.value;
181.        var cell1 = row.insertCell(9);
182.        cell1.innerHTML = form.recive_by.value;
183.        var cell1 = row.insertCell(10);
184.        cell1.innerHTML = form.repair_at.value;
185.        var cell1 = row.insertCell(11);
186.         
187.        innervalue = "";
188.        innervalue += '<input type="hidden" name="repairlist['+indexlist+'][date_repair]" value="'+form.date_repair.value+'" />';
189.        innervalue += '<input type="hidden" name="repairlist['+indexlist+'][rid]" value="'+form.rid[form.rid.selectedIndex].value+'" />';
190.        innervalue += '<input type="hidden" name="repairlist['+indexlist+'][repair_number]" value="'+form.repair_number.value+'" />';
191.        innervalue += '<input type="hidden" name="repairlist['+indexlist+'][part_number]" value="'+form.part_number.value+'" />';
192.        innervalue += '<input type="hidden" name="repairlist['+indexlist+'][repair_detail]" value="'+form.repair_detail.value+'" />';
193.        innervalue += '<input type="hidden" name="repairlist['+indexlist+'][amount]" value="'+form.amount.value+'" />';
194.        innervalue += '<input type="hidden" name="repairlist['+indexlist+'][price_perunit]" value="'+form.price_perunit.value+'" />';
195.        innervalue += '<input type="hidden" name="repairlist['+indexlist+'][price_discount]" value="'+form.price_discount.value+'" />';
196.        innervalue += '<input type="hidden" name="repairlist['+indexlist+'][price_total]" value="'+form.price_total.value+'" />';
197.        innervalue += '<input type="hidden" name="repairlist['+indexlist+'][recive_by]" value="'+form.recive_by.value+'" />';
198.        innervalue += '<input type="hidden" name="repairlist['+indexlist+'][repair_at]" value="'+form.repair_at.value+'" />';
199.        innervalue += '<input type="hidden" name="repairlist['+indexlist+'][repair_remark]" value="'+form.repair_remark.value+'" />';
200.        innervalue += '<input type="hidden" name="repairlist['+indexlist+'][mile]" value="'+form.mile.value+'" />';
201.        innervalue += '<input name="" type="button" value="ลบ" onclick="removeRows(\''+"rows"+indexlist+'\');" />';
202.        cell1.innerHTML = innervalue;
203.        cell1.setAttribute("rowSpan",2);
204.         
205.        rcount = tr.rows.length;
206.        row = tr.insertRow(rcount);
207.        cell1 = row.insertCell(0);
208.        cell1.innerHTML = "เลขไมล์";
209.        cell1 = row.insertCell(1);
210.        cell1.innerHTML = form.mile.value;
211.        cell1 = row.insertCell(2);
212.        cell1.innerHTML = "หมายเหตุ";
213.        cell1 = row.insertCell(3);
214.        cell1.innerHTML = form.repair_remark.value;
215.        cell1.setAttribute("colSpan",8);
216.         
217.        indexlist++;
218.         
219.        form.rid.selectedIndex=0;
220.        form.part_number.value="";
221.        form.repair_detail.value="";
222.        form.amount.value="";
223.        form.price_perunit.value="";
224.        form.price_discount.value="";
225.        form.price_total.value="";
226.        form.recive_by.value="";
227.        form.repair_at.value="";
228.        form.repair_remark.value="";
229.    }
230.}
231.function removeRows(rowid){
232.    var tr = document.getElementById('repairlist');
233.    for(var i=0;i<tr.rows.length;i++){
234.        if(tr.rows[i].id == rowid){
235.            tr.deleteRow(i);
236.            tr.deleteRow(i);
237.            break;
238.        }
239.    }
240. 
241.}
242.        function gencarlist(id){
243.            if(id.selectedIndex > 0){
244.            var selectid = id[id.selectedIndex].value;
245.            var carlist = new Array();
246.                        var carlicense = document.getElementById('carlicense');
247.             
248.            var oplength = carlicense.options.length;
249.             
250.            while(oplength){
251.                oplength = carlicense.options.length;
252.                for(i=0;i<=oplength;i++){
253.                    carlicense.options[i] = null;
254.                }
255.            }
256.            carlicense.options[0] = new Option('select car','0');
257.                for(i=1;i<=carlist[selectid].length;i+=2){
258.                    carlicense.options[(i+1)/2] = new Option(carlist[selectid][i],carlist[selectid][i-1]);
259.                }
260.            }
261.        }
262.        function save(){
263.            document.adminForm.step.value='3';
264.            document.adminForm.submit();
265.        }
266.        </script>
267.</div>
268. 
269.</body>
270.<script type="text/javascript">
271.$(function(){
272.     $("#datepicker").datepicker({ dateFormat: "yy-mm-dd" }).val('<? $date = date("Y-m-d");echo $date?>')
273.      
274.});
275.</script></html>
276. <link href="../jQueryui/jQuery-ui.css" rel="stylesheet" type="text/css"/>

[/php]

insertData.php

Code (PHP)
01.<strong>Code (PHP)</strong>
02.[php]<?php
03.  include('../config.php');
04.   
05.    if($_POST[save])
06.    {
07.     foreach ($_POST['rid'] as $key => $value)
08.        {
09.            $rid = $_POST["rid"][$key];
10.            $date_repair = $_POST["date_repair"][$key];
11.            $repair_number = $_POST["repair_number"][$key];
12.             $repair_detail = $_POST["repair_detail"][$key];
13.             $part_numbert = $_POST["part_number"][$key];
14.              $amount = $_POST["amount"][$key];
15.               $price_perunit = $_POST["price_perunit"][$key];
16.                $price_discount = $_POST["price_discount"][$key];
17.                 $price_total = $_POST["price_total"][$key];
18.                  $recive_by = $_POST["recive_by"][$key];
19.                   $repair_at = $_POST["repair_at"][$key];
20.                    $mile = $_POST["mile"][$key];
21.                    $repair_remark = $_POST["repair_remark"][$key];
22.   
23.            $strsql = mysql_query("insert into repair_table values
24.             ('',
25.            '$rid',
26.            '$date_repair',
27.            '$repair_number',
28.            '$repair_detail',
29.            '$part_number',
30.            '$amount',
31.            '$price_perunit',
32.            '$price_discount',
33.            '$price_total',
34.            '$recive_by',
35.            '$repair_at',
36.            '$mile'
37.            '$repair_remark')");       
38.         
39.       mysql_query($strsql);
40.if($strsql){
41.       exit ("<script> window.location='repair_input.php';</script>");
42. 
43.}
44.    }
45.        }
46.         ?>
47.    
48.    

[/php]



Tag : PHP



ประวัติการแก้ไข
2017-01-18 10:16:55
2017-01-18 10:18:12
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2017-01-18 10:12:43 By : panya@ots View : 640 Reply : 2
 

 

No. 1



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ถ้าลง HTML Element จะต้องอ่านค่ามันลง Form Element ก่อนที่จะ Submit ส่งไปครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-01-18 15:59:00 By : mr.win
 

 

No. 2



โพสกระทู้ ( 111 )
บทความ ( 0 )



สถานะออฟไลน์


รบกวนขอตัวอย่างหน่อยซิครับ ขอบพระคุณมากครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-01-18 17:49:15 By : panya@ots
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ขอความช่วยเหลือครับ จะต้องเขียน code ที่ถูกต้องเพื่อที่จะ insert รายการของ cell1.innerHTML ไปฐานข้อมูลอย่างไรครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่