|
|
|
ทำไมเพิ่มข้อมูลลงฐานข้อมูลไม่ได้ค่ะ ใครรู้ช่วยตอบหน่อย ผิดตรงไหน พึ่งหัดทำยังแก้โค้ดไม่ค่อยถูก |
|
|
|
|
|
|
|
หน้าFormCode (PHP)
<?php
ob_start();
Session_Start();
Include("connect1.php");
?>
<HTML><HEAD>
<meta http-equiv="Content-Language" content="en-us">
<LINK
href="index.php_files/text.css" type=text/css
rel=stylesheet>
<LINK
href="index.php_files/text.css" type=text/css rel=stylesheet>
<TITLE></TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874"><LINK
href="index.php_files/text.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.2900.5512" name=GENERATOR>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
<style type="text/css">
<!--
.style1 {color: #0099FF}
.style4 {
color: #FFFF66;
font-weight: bold;
}
-->
</style>
</HEAD>
<BODY bgProperties=fixed leftMargin=0 topMargin=0 rightMargin=0
marginheight="0" marginwidth="0" background="../bg/t_274733gif.gif">
<div align="center">
<TABLE cellSpacing=0 cellPadding=0 width="656" border=0>
<TBODY>
<tr>
<td bgcolor="#FFFFFF" width="656" >
<div align="center">
<!--webbot BOT="GeneratedScript" PREVIEW=" " startspan --><script Language="JavaScript" Type="text/javascript"><!--
function FrontPage_Form1_Validator(theForm)
{
if (theForm.barcode_id.value == "")
{
alert("Please enter a value for the \"บาร์โค้ดสินค้า\" field.");
theForm.barcode_id.focus();
return (false);
}
if (theForm.barcode_id.value.length < 1)
{
alert("Please enter at least 1 characters in the \"บาร์โค้ดสินค้า\" field.");
theForm.barcode_id.focus();
return (false);
}
if (theForm.product_id.value == "")
{
alert("Please enter a value for the \"รหัสสินค้า\" field.");
theForm.product_id.focus();
return (false);
}
if (theForm.product_id.value.length < 1)
{
alert("Please enter at least 1 characters in the \"รหัสสินค้า\" field.");
theForm.product_id.focus();
return (false);
}
if (theForm.deception.value == "")
{
alert("Please enter a value for the \"ชื่อสินค้า\" field.");
theForm.deception.focus();
return (false);
}
if (theForm.deception.value.length < 1)
{
alert("Please enter at least 1 characters in the \"ชื่อสินค้า\" field.");
theForm.deception.focus();
return (false);
}
if (theForm.unitname.value == "")
{
alert("Please enter a value for the \"หน่วยสินค้า\" field.");
theForm.unitname.focus();
return (false);
}
if (theForm.unitname.value.length < 1)
{
alert("Please enter at least 1 characters in the \"หน่วยสินค้า\" field.");
theForm.unitname.focus();
return (false);
}
if (theForm.car_id.value == "")
{
alert("Please enter a value for the \"รุ่นรถ\" field.");
theForm.car_id.focus();
return (false);
}
if (theForm.car_id.value.length < 1)
{
alert("Please enter at least 1 characters in the \"รุ่นรถ\" field.");
theForm.car_id.focus();
return (false);
}
if (theForm.spare_type.value == "")
{
alert("Please enter a value for the \"ประเภทอะไหล่\" field.");
theForm.spare_type.focus();
return (false);
}
if (theForm.spare_type.value.length < 1)
{
alert("Please enter at least 1 characters in the \"ประเภทอะไหล่\" field.");
theForm.spare_type.focus();
return (false);
}
return (true);
}
//--></script><!--webbot BOT="GeneratedScript" endspan --><form method="POST" action="productsave.php" onSubmit="return FrontPage_Form1_Validator(this)" language="JavaScript" name="FrontPage_Form1" enctype="multipart/form-data">
<table width="618" border="1" cellpadding="1" cellspacing="1" bordercolor="#000066" id="table1">
<tr>
<td align="center" bgcolor="#0033CC" colspan="2">
<span class="style4">
เพิ่มข้อมูล ตาราง: สินค้า</span></td>
</tr>
<tr>
<td align="right" bgcolor="#CCCCCC" width="112" background="pic/bg-box-friends.gif">
<span style="FONT-SIZE: 11pt; FONT-WEIGHT: 700" lang="th">บาร์โค้ดสินค้า</span></td>
<td align="left" width="493" bgcolor="#CCCCCC" background="pic/bg-box-friends.gif">
<!--webbot bot="Validation" s-display-name="บาร์โค้ดสินค้า" b-value-required="TRUE" i-minimum-length="1" -->
<input name="barcode_id" type="text" id="barcode_id" size="22"></td>
</tr>
<tr>
<td align="right" bgcolor="#CCCCCC" width="112" background="pic/bg-box-friends.gif">
<span style="FONT-SIZE: 11pt; FONT-WEIGHT: 700" lang="th">รหัสสินค้า</span></td>
<td align="left" width="493" bgcolor="#CCCCCC" background="pic/bg-box-friends.gif">
<!--webbot bot="Validation" s-display-name="รหัสสินค้า" b-value-required="TRUE" i-minimum-length="1" -->
<input name="product_id" type="text" id="product_id" size="22"></td>
</tr>
<tr>
<td align="right" bgcolor="#CCCCCC" width="112" background="pic/bg-box-friends.gif">
<span style="FONT-SIZE: 11pt; FONT-WEIGHT: 700" lang="th">ชื่อสินค้า</span></td>
<td align="left" width="493" bgcolor="#CCCCCC" background="pic/bg-box-friends.gif">
<!--webbot bot="Validation" s-display-name="ชื่อสินค้า" b-value-required="TRUE" i-minimum-length="1" --><input name="deception" type="text" id="deception" size="54"></td>
</tr>
<tr>
<td align="right" bgcolor="#CCCCCC" width="112" background="pic/bg-box-friends.gif">
<span style="font-weight: 700; font-size: 11pt" lang="th">หน่วย</span></td>
<td align="left" width="493" bgcolor="#CCCCCC" background="pic/bg-box-friends.gif">
<span class="style1 style15 style8">
<select name="unitname" id="title_name0" size="1"
>
<option value="ลูก" selected>ลูก</option>
<option value="อัน">อัน</option>
<option value="แผง">แผง</option>
<option value="ชุด">ชุด</option>
<option value="กล่อง">กล่อง</option>
<option value="แพ๊ค">แพ๊ค</option>
<option value="ตัว">ตัว</option>
<option value="แกลลอน">แกลลอน</option>
<?
While($result = mysql_fetch_array($db_query)){
?>
<?}?>
</select></span></td>
</tr>
<tr>
<td align="right" bgcolor="#CCCCCC" width="112" background="pic/bg-box-friends.gif">
<span style="FONT-SIZE: 11pt; FONT-WEIGHT: 700" lang="th">ราคา/หน่วย</span></td>
<td align="left" width="493" bgcolor="#CCCCCC" background="pic/bg-box-friends.gif">
<!--webbot bot="Validation" s-display-name="ราคา" s-data-type="Number" s-number-separators="x." b-value-required="TRUE" i-minimum-length="1" -->
<input type="text" name="pro_price" size="54"></td>
</tr>
<tr>
<td align="right" bgcolor="#CCCCCC" width="112" background="pic/bg-box-friends.gif">
<span style="FONT-SIZE: 11pt; FONT-WEIGHT: 700" lang="th">รูปภาพ</span></td>
<td align="left" width="493" bgcolor="#CCCCCC" background="pic/bg-box-friends.gif">
<input type="file" name="filUpload"></td>
</tr>
<tr>
<td align="right" bgcolor="#CCCCCC" width="112" background="pic/bg-box-friends.gif">
<span style="FONT-SIZE: 11pt; FONT-WEIGHT: 700" lang="th">รายละเอียด</span></td>
<td align="left" width="493" bgcolor="#CCCCCC" background="pic/bg-box-friends.gif">
<!--webbot bot="Validation" s-display-name="รายละเอียด" b-value-required="TRUE" i-minimum-length="1" -->
<textarea name="detail" cols="52" rows="6" id="detail"></textarea></td>
</tr>
<tr>
<td align="right" bgcolor="#CCCCCC" width="112" background="pic/bg-box-friends.gif">
<span style="FONT-SIZE: 11pt; FONT-WEIGHT: 700" lang="th">จำนวน</span></td>
<td align="left" width="493" bgcolor="#CCCCCC" background="pic/bg-box-friends.gif">
<!--webbot bot="Validation" s-display-name="จำนวน" s-data-type="Integer" s-number-separators="x" b-value-required="TRUE" i-minimum-length="1" -->
<input name="stock" type="text" id="stock" size="54"></td>
</tr>
<tr>
<td align="right" bgcolor="#CCCCCC" width="112" background="pic/bg-box-friends.gif">
<span style="FONT-SIZE: 11pt; FONT-WEIGHT: 700" lang="th">Supplire1</span></td>
<td align="left" width="493" bgcolor="#CCCCCC" background="pic/bg-box-friends.gif">
<!--webbot bot="Validation" s-display-name="ชื่อสินค้า" b-value-required="TRUE" i-minimum-length="1" --><input name="Supplire1" type="text" id="Supplire1" size="54"></td>
</tr>
<tr>
<td align="right" bgcolor="#CCCCCC" width="112" background="pic/bg-box-friends.gif"><span style="FONT-SIZE: 11pt; FONT-WEIGHT: 700">Supplire2</span></td>
<td align="left" width="493" bgcolor="#CCCCCC" background="pic/bg-box-friends.gif">
<!--webbot bot="Validation" s-display-name="ชื่อสินค้า" b-value-required="TRUE" i-minimum-length="1" --><input name="Supplire2" type="text" id="Supplire2" size="54"></td>
</tr>
<tr>
<td align="right" bgcolor="#CCCCCC" width="112" background="pic/bg-box-friends.gif"><span style="FONT-SIZE: 11pt; FONT-WEIGHT: 700">Supplire3</span></td>
<td align="left" width="493" bgcolor="#CCCCCC" background="pic/bg-box-friends.gif">
<!--webbot bot="Validation" s-display-name="ชื่อสินค้า" b-value-required="TRUE" i-minimum-length="1" --><input name="Supplire2" type="text" id="Supplire2" size="54"></td>
</tr>
<tr>
<td align="right" bgcolor="#CCCCCC" width="112" background="pic/bg-box-friends.gif">
<span style="font-weight: 700; font-size: 11pt" lang="th">รุ่นรถ</span></td>
<td align="left" width="493" bgcolor="#CCCCCC" background="pic/bg-box-friends.gif">
<span class="style1 style15 style8">
<?php
include"connect1.php";
?>
<select name="car_id" id="car_id">
<?php
$q="select * from car ";
$qr=mysql_query($q);
while($rs=mysql_fetch_array($qr)){
?>
<option value="<?=$rs['car_id']?>"><?=$rs['car_name']?></option>
<?php } ?>
</select>
</span></td>
</tr>
<tr>
<td align="right" bgcolor="#CCCCCC" width="112" background="pic/bg-box-friends.gif">
<span style="font-weight: 700; font-size: 11pt" lang="th">ประเภทอะไหล่</span></td>
<td align="left" width="493" bgcolor="#CCCCCC" background="pic/bg-box-friends.gif">
<span class="style1 style15 style8">
<?php
include"connect1.php";
?>
<select name="spare_type_id" id="spare_type_id">
<?php
$q="select * from spare_type ";
$qr=mysql_query($q);
while($rs=mysql_fetch_array($qr)){
?>
<option value="<?=$rs['spare_type_id']?>"><?=$rs['spare_type_name']?></option>
<?php } ?>
</select> </span></td>
</tr>
<tr>
<td bgcolor="#008080" align="center" colspan="2" background="pic/top_tab_bg.gif">
<font color="#FF0000">
<input type="submit" value="บันทึกข้อมูล" name="B1">
<label>
<input name="B2" type="reset" id="B2" value="Reset">
</label></td>
</tr>
</table>
</form>
</div>
</td>
</tr>
</TBODY></TABLE>
</div>
</BODY></HTML>
หน้า ADD ข้อมูล
Code (PHP)
<?php
ob_start();
Session_Start();
Include("connect1.php");
$id = $_POST['id'];
$barcode_id = $_POST['barcode_id'];
$product_id = $_POST['product_id'];
$deception = $_POST['deception'];
$unitname = $_POST['unitname'];
$pro_price = $_POST['pro_price'];
$detail = $_POST['detail'];
$stock = $_POST['stock'];
$supplier1 = $_POST['supplier1'];
$supplier2 = $_POST['supplier2'];
$supplier3 = $_POST['supplier3'];
$car_id = $_POST['car_id'];
$spare_type_id = $_POST['spare_type_id'];
$tb="categories";
$sql="select * from $tb where id='$id'";
$db_query=mysql_db_query($db,$sql);
$num_rows=mysql_num_rows($db_query);
if($num_rows>0){?>
<script Language="JavaScript" Type="text/javascript">
alert("มีรหัสสินค้าที่ซ้ำกัน");
</script>
<?}else{
$sql="select * from $tb";
$db_query=mysql_db_query($db,$sql);
$num_rows=mysql_num_rows($db_query);
$x=$num_rows++;
if(copy($_FILES["filUpload"]["tmp_name"],"picture/$x".$_FILES["filUpload"]["name"]))
{
mysql_query("INSERT INTO $tb (id,barcode_id,product_id,deception,unitname,pro_price,pro_pic,detail,stock,supplier1,supplier2,supplier3,car_id,spare_type_id) values ('$id','$barcode_id','$product_id','$deception','$unitname','$pro_price','$x".$_FILES["filUpload"]["name"]."','$detail','$stock','$supplier1','$supplier2','$supplier3','$car_id','$spare_type_id')") or die ("Add ข้อมูลลง Table ไม่ได้ ");
}else{
$p='Nopic.jpg';
mysql_query("INSERT INTO $tb (id,barcode_id,product_id,deception,unitname,pro_price,pro_pic,detail,stock,supplier1,supplier2,supplier3,car_id,spare_type_id) values ('$id','$barcode_id','$product_id','$deception','$unitname','$pro_price','$p','$detail','$stock','$supplier1','$supplier2','$supplier3','$car_id','$spare_type_id')") or die ("Add ข้อมูลลง Table ไม่ได้ ");
}
header("refresh:0;url=productlist.php");
?>
<script Language="JavaScript" Type="text/javascript">
alert("เสร็จเรียบร้อย ");
</script>
<?}?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2010-08-03 15:49:27 |
By :
mnmnmn |
View :
917 |
Reply :
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ให้ลองทดสอบดูนะครับว่า $_POST ไหม โดยการ echo ออกมาดูนะครับ ว่ามันรับค่ามาจาก from เปล่า
|
|
|
|
|
Date :
2010-08-03 15:57:45 |
By :
mosaddzero |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่แน่ใจนะครับ แต่ที่เห็นแบบผ่านๆ เหมือนจะลืม values() ครับ
insert into [ตาราง] values('f1','f2','...')
นะคิดว่าตรงนี้
|
|
|
|
|
Date :
2010-08-03 15:58:25 |
By :
compeng |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
กำหนดแล้วนะคะ ค่า values() ตรงนี้ค่ะ แต่ run แล้ว แต่โชว์ว่า "add ข้อมูลลง table" ไม่ได้ ค่ะ
Code (PHP)
$tb="categories";
$sql="select * from $tb where id='$id'";
$db_query=mysql_db_query($db,$sql);
$num_rows=mysql_num_rows($db_query);
if($num_rows>0){?>
<script Language="JavaScript" Type="text/javascript">
alert("มีรหัสสินค้าที่ซ้ำกัน");
</script>
<?}else{
$sql="select * from $tb";
$db_query=mysql_db_query($db,$sql);
$num_rows=mysql_num_rows($db_query);
$x=$num_rows++;
if(copy($_FILES["filUpload"]["tmp_name"],"picture/$x".$_FILES["filUpload"]["name"]))
{
mysql_query("INSERT INTO $tb (id,barcode_id,product_id,deception,unitname,pro_price,pro_pic,detail,stock,supplier1,supplier2,supplier3,car_id,spare_type_id) values ('$id','$barcode_id','$product_id','$deception','$unitname','$pro_price','$x".$_FILES["filUpload"]["name"]."','$detail','$stock','$supplier1','$supplier2','$supplier3','$car_id','$spare_type_id')") or die ("Add ข้อมูลลง Table ไม่ได้ ");
}else{
$p='Nopic.jpg';
mysql_query("INSERT INTO $tb (id,barcode_id,product_id,deception,unitname,pro_price,pro_pic,detail,stock,supplier1,supplier2,supplier3,car_id,spare_type_id) values ('$id','$barcode_id','$product_id','$deception','$unitname','$pro_price','$p','$detail','$stock','$supplier1','$supplier2','$supplier3','$car_id','$spare_type_id')") or die ("Add ข้อมูลลง Table ไม่ได้ ");
}
|
|
|
|
|
Date :
2010-08-03 16:09:12 |
By :
mnmnmn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลอง เอาตัวแปร มารับก่อนครับ แล้ว echo ตัวแปรนั้นออกมา เอาค่าที่ได้ ไป query ใน mysql โดยตรงครับว่าผ่านไหม ถ้าไม่ผ่านต้องแก้ sql ครับ
|
|
|
|
|
Date :
2010-08-03 16:11:53 |
By :
akava |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
พอมีตัวอย่างมั้ยคะ
|
|
|
|
|
Date :
2010-08-03 16:15:17 |
By :
mnmnmn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
ช่วย test ข้อมูลด้วยนะครับ
$id = $_POST['id'];
$barcode_id = $_POST['barcode_id'];
$product_id = $_POST['product_id'];
$deception = $_POST['deception'];
$unitname = $_POST['unitname'];
$pro_price = $_POST['pro_price'];
$detail = $_POST['detail'];
$stock = $_POST['stock'];
$supplier1 = $_POST['supplier1'];
$supplier2 = $_POST['supplier2'];
$supplier3 = $_POST['supplier3'];
$car_id = $_POST['car_id'];
$spare_type_id = $_POST['spare_type_id'];
echo "
id = $_POST['id']<br>
barcode_id = $_POST['barcode_id']<br>
product_id = $_POST['product_id']<br>
deception = $_POST['deception']<br>
unitname = $_POST['unitname']<br>
pro_price = $_POST['pro_price']<br>
detail = $_POST['detail']<br>
stock = $_POST['stock']<br>
supplier1 = $_POST['supplier1']<br>
supplier2 = $_POST['supplier2']<br>
supplier3 = $_POST['supplier3']<br>
car_id = $_POST['car_id']<br>
spare_type_id = $_POST['spare_type_id']<br>
";
ลองเช็ค ข้อมูลครับว่าถูกส่งมาจาก form หรือป่าว
|
|
|
|
|
Date :
2010-08-03 16:16:24 |
By :
compeng |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มันได้อย่างเนี้ย
1234562345678ÁÔé§ ÁÔé§ÅÙ¡120¹èÒÃÑ¡¨Ñ§24345Add ¢éÍÁÙÅŧ Table äÁèä´é
ไม่เข้าใจเลย
|
|
|
|
|
Date :
2010-08-03 16:36:52 |
By :
mnmnmn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองเปลี่ยน charset ดูครับ
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">// ตัวเดิม
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">// ตัวใหม่
แล้วลองทดสอบดู
Code (PHP)
ช่วย test ข้อมูลด้วยนะครับ
$id = $_POST['id'];
$barcode_id = $_POST['barcode_id'];
$product_id = $_POST['product_id'];
$deception = $_POST['deception'];
$unitname = $_POST['unitname'];
$pro_price = $_POST['pro_price'];
$detail = $_POST['detail'];
$stock = $_POST['stock'];
$supplier1 = $_POST['supplier1'];
$supplier2 = $_POST['supplier2'];
$supplier3 = $_POST['supplier3'];
$car_id = $_POST['car_id'];
$spare_type_id = $_POST['spare_type_id'];
echo "
id = $id<br>
barcode_id = $barcode_id<br>
product_id = $product_id<br>
deception = $deception<br>
unitname = $unitname<br>
pro_price = $pro_price<br>
detail = $detail<br>
stock = $stock<br>
supplier1 = $supplier1<br>
supplier2 = $supplier2<br>
supplier3 = $supplier3<br>
car_id = $car_id<br>
spare_type_id = $spare_type_id<br>
";
|
ประวัติการแก้ไข 2010-08-04 01:42:05
|
|
|
|
Date :
2010-08-04 01:38:06 |
By :
mosaddzero |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|