|
 |
|
ขอความช่วยเหลือ เรื่องหน้า page Edit ครับ มันขึ้นเป็น text แทนที่จะขึ้นหน้าปรกติ |
|
 |
|
|
 |
 |
|
บอกก่อนว่าผมยังไม่เคยเขียน php มาก่อน เลยเริ่มจากแกะตัวอย่าง code จากหนังสือเล่มนึง แล้วเอามาแปลงเป็นของตัวเองเพื่อศึกษาดู
ซึ่งก็ทำผ่านมาได้เรื่อยๆ จนเริ่มมาติดตรงหน้า edit เนี่ยเหละครับ
คือแบบนี้ครับ อันนี้เป็นหน้าหลักโปรแกรมนะครับ

ซึงผมจะทำการเข้าที่หน้าแก้ไขข้อมูล (ด้านบน) ซึ่งพอกดเข้ามาปุ๊บแทนที่มันจะเป็นหน้าปรกติ มันดันเป็นแบบนี้

คือเป็น text มาล้วนๆเลย ผมต้องกด F5 1ครั้ง ถึงจะเป็นแบบปรกติคือแบบนี้

ทีนี้ผมก็เลยลองทำการ edit ข้อมูลดู


แต่พอกด ok ปุ๊บ

มันกลับขึ้น text ล้วนๆแบบนี้อีกแล้ว
ซึ่งผมลองกด f5 รีเฟรสหน้าใหม่อีกที มันก็ขึ้นแบบนี้

จากนั้นก็ทำอะไรไม่ได้เลย กดรีไทน์ก็กลับมา text เหมือนเดิม (ข้อมูลในดาต้าเบสก็ไม่เปลี่ยนด้วย ยังเหมือนเดิม)
ก่อนหน้านั้นหน้าเพิ่มสินค้าผมทำได้แล้วครับรันออกมาปรกติ มีปัญหากับหน้า edit เนี่ยเหละครับ
อันนี้เป็น code ทั้งหมดในหน้า Editproduct.php ที่มีปัญหาครับ
Code (PHP)
<?
header("Content-Type: text/plain; charset=TIS-620");
session_start();
$sessionID= session_id();
$removeProductID = $_POST['ProductID'];
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-color: #FFFFFF;
}
-->
</style>
<script type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<table width="1008" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="134" rowspan="2" valign="top"><img src="./pic/Ntopleft.gif" width="134" height="142" /></td>
<td height="97" colspan="2" valign="top"><img src="./pic/Ntopleft2.gif" alt="" width="56" height="97" /><a href="Addproduct.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image10','','pic/mbook1.gif',1)"><img src="pic/mbook.gif" alt="" name="Image10" width="113" height="96" border="0" id="Image10" /></a><a href="Editproduct.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image11','','pic/mMaster1.gif',1)"><img src="pic/mMaster1.gif" alt="" name="Image11" width="94" height="97" border="0" id="Image11" /></a><a href="Removeproduct.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image12','','pic/mReport1.gif',1)"><img src="pic/mReport.gif" alt="" name="Image12" width="118" height="97" border="0" id="Image12" /></a><img src="./pic/topmid2.gif" alt="" width="277" height="97" /></td>
<td width="100"> </td>
</tr>
<tr>
<td width="4" height="36"> </td>
<td width="770" rowspan="2" valign="top"><p><img src="./pic/mid12.jpg" width="115" height="64" /><img src="./pic/mid2.jpg" width="110" height="66" /><img src="./pic/mid2.jpg" width="110" height="66" /><img src="./pic/mid2.jpg" width="104" height="66" /><img src="./pic/mid2.jpg" width="103" height="66" /><img src="./pic/mid3.jpg" width="116" height="66" /></p></td>
<td> </td>
</tr>
<tr>
<td rowspan="3" valign="top" ><!--DWLayoutEmptyCell--> </td>
<td height="30"></td>
<td></td>
</tr>
<tr>
<td height="26"></td>
<td><br><?
include ("config.inc.php");
if ($ProductID>0){
$sql = "UPDATE `stock`.`product`
SET `name` = '$Pname',
`price` = '$Pprice'
WHERE `product`.`proid` ='$ProductID' ;";
mysql_query($sql);
}
$sql = "SELECT * FROM `product`";
$result = mysql_query($sql);
$totalPrice=0;
echo"<table width='75%' border='1' bordercolor='#A59A1B' bgcolor='#D3BC38' ><tr align='center'><td><b>ภาพสินค้า</b></td>
<td> <b>รหัสสินค้า</b></td>
<td> <b>ชื่อสินค้า</b></td>
<td><b>ราคา</b></td>
<td><b>แก้ไขจำนวนสินค้า</b>
<td><b>แก้ไขสินค้า</b>
<td><b></b>
</td></tr>";
while($row=mysql_fetch_array($result)){
$ProductID = $row["proid"];
$productName = $row["name"];
$productPrice = $row["price"];
$productqty = $row["qty"];
$pic = $row["pic"];
echo "<tr bgcolor='#D3BC38' align='center'><form id='form1' name='form1' method='post' action='Editproduct.php'>";
echo"<td><img src='$pic' width=150 height=150 ></td>";
echo "<td>$ProductID<input name='ProductID' type='hidden' value='$ProductID'></td><td><input name='Pname' type='text' value='$productName'></td>";
echo "<td><input name='Pprice' type='text' value='$productPrice'></td>";
echo "<td><input name='qty' type='text' value='$productqty'></td>";
echo "<td><input type='submit' name='Delete' id='Edit' value='Edit' onclick=" ?>"return confirm('คุณแน่ใจว่าต้องการแก้ไขข้อมูลนี้หรือไม่ ? ')" /><? "/>";
echo "</td></form></tr>";
}
echo "</table>";
?></br></td>
<td></td>
</tr>
<tr>
<td height="29" ></td>
<td rowspan="2">
<h3 align="left"> </h3></td>
<td></td>
</tr>
<tr>
</tr>
</table>
</body>
</html>
อันนี้เป็นตารางที่เกี่ยวข้องครับผมแนบไว้ให้ดูด้วยเผื่อว่าติดขัดตรงไหน

ช่วยดูให้ทีครับว่าผมทำผิดตรงไหน ขอบคุณครับ
Tag : PHP

|
ประวัติการแก้ไข 2011-11-23 04:02:06
|
 |
 |
 |
 |
Date :
2011-11-22 18:25:32 |
By :
TopKisser |
View :
1032 |
Reply :
19 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้บรรทัดที่ 2 เป็น
header("Content-Type: text/html; charset=TIS-620");
|
 |
 |
 |
 |
Date :
2011-11-22 20:18:05 |
By :
nimporn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ฐานข้อมูล มีเทเบิลอะไรบ้าง ขอดูฟิลด์ด้วย
|
 |
 |
 |
 |
Date :
2011-11-22 20:38:20 |
By :
nimporn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีตามนี้ครับ
ฐานข้อมูลชื่อ stock ส่วน table ที่เกี่ยวข้องกับหน้านี้คือ product ครับ

ส่วนอันนี้ข้อมูลที่อยู่ใน table product ครับ (ยังไม่ได้ใส่อะไรมาก)

|
 |
 |
 |
 |
Date :
2011-11-22 20:46:03 |
By :
TopKisser |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โอเค ก่อนอื่น รับค่าที่ส่งมาจากฟอร์มก่อน ด้วย
$ProductID=$_POST['ProductID'];
$qty=$_POST['qty'];
$Pprice=$_POST['Pprice'];
$Pname=$_POST['Pname'];
เอาไว้บรรทัดก่อนหน้า include ("config.inc.php"); เลย
|
 |
 |
 |
 |
Date :
2011-11-22 20:49:34 |
By :
nimporn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วก็แก้ query ตามนี้
Code (PHP)
if ($ProductID>0) {
$sql = "UPDATE product
SET name = '$Pname',
price = '$Pprice',
qty = '$qty'
WHERE proid ='$ProductID' ";
mysql_query($sql);
}
$sql = "SELECT * FROM product";
$result = mysql_query($sql);
|
ประวัติการแก้ไข 2011-11-22 20:53:52
 |
 |
 |
 |
Date :
2011-11-22 20:52:55 |
By :
nimporn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองแล้วครับยังไม่ได้ครับ
คิดว่าน่าจะเป็นเพราะว่ามันไม่มีค่าอะไรส่งมา
เพราะว่าตัวแปลที่รับค่า
$ProductID=$_POST['ProductID'];
$qty=$_POST['qty'];
$Pprice=$_POST['Pprice'];
$Pname=$_POST['Pname'];
พวกนี้มันอยู่ในหน้า add product

แต่จุดประสงที่ผมจะทำคือ
อันนี้เป็นหน้าหลักครับ

อันนี้ code หน้าหลักครับ (ขอลงไว้ละกัน เผื่อผมผิด)
Code (PHP)
<?
include ("config.inc.php");
$sql = "SELECT * FROM `product`";
$result = mysql_query($sql);
$totalPrice=0;
echo"<table width='75%' border='1' bordercolor='#A59A1B' bgcolor='#D3BC38' ><tr align='center'><td><b>ภาพสินค้า</b></td>
<td> <b>รหัสสินค้า</b></td>
<td> <b>ชื่อสินค้า</b></td>
<td><b>ราคา</b></td>
<td><b>จำนวนที่มี</b></td>
<td><b></b>
</td></tr>";
while($row=mysql_fetch_array($result)){
$ProductID = $row["proid"];
$productName = $row["name"];
$productPrice = $row["price"];
$productqty = $row["qty"];
$pic = $row["pic"];
echo "<tr bgcolor='#D3BC38' align='center'>";
echo"<td><img src='$pic' width=150 height=150 ></td>";
echo "<td>$ProductID</td><td>$productName</td>";
echo "<td>$productPrice บาท</td>";
echo "<td>$productqty</td>";
echo "</tr>";
}
echo "</table>";
?>
ซึ่งผมใช้วิธีดึงจาก table มาโชวเฉยๆอะ
แล้วพอผมกด แก้ไขสินค้า ก็จะเข้าหน้าแบบนี้

ซึ่งถ้ากด edit มันก็น่าจะแก้ใขในดาต้าเบสให้เลย แต่ไม่รู้ว่าผมทำอะไรผิดไป -.-
|
 |
 |
 |
 |
Date :
2011-11-22 21:02:04 |
By :
TopKisser |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันก็แก้ไขได้นิ ลองเอาไปทำดูแล้ว ผลเป็นแบบภาพแนบ



คุณลอง echo ดูค่าที่ส่งออกมาในทุกช่วง { } ของเงื่อนไขดูซิว่ามันส่งค่าอะไรมาบ้าง
|
 |
 |
 |
 |
Date :
2011-11-23 05:35:58 |
By :
nimporn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ประมาณนี้พอได้ไหมครับ
Code (PHP)
<?
$ProductID=$_POST['ProductID'];
$qty=$_POST['qty'];
$Pprice=$_POST['Pprice'];
$Pname=$_POST['Pname'];
include ("config.inc.php");
if (empty($ProductID)) {echo "ตัวแปรProductID ไม่ได้เก็บข้อมูลใดๆไว้<br>\n";} else {echo "ตัวแปร ProductID มีข้อมูลอยู่แล้ว<br>\n";}
if (empty($Pname)) {echo "ตัวแปร Pname ไม่ได้เก็บข้อมูลใดๆไว้<br>\n";} else {echo "ตัวแปร Pname มีข้อมูลอยู่แล้ว<br>\n";}
if (empty($Pprice)) {echo "ตัวแปร Pprice ไม่ได้เก็บข้อมูลใดๆไว้<br>\n";} else {echo "ตัวแปร Pprice มีข้อมูลอยู่แล้ว<br>\n";}
if (empty($textqty)) {echo "ตัวแปร textqty ไม่ได้เก็บข้อมูลใดๆไว้<br>\n";} else {echo "ตัวแปร textqty มีข้อมูลอยู่แล้ว<br>\n";}
if ($ProductID>0){
$sql = "UPDATE product
SET name = '$Pname',
price = '$Pprice',
qty = '$textqty'
WHERE proid ='$ProductID' ;";
mysql_query($sql);
}
$sql = "SELECT * FROM `product`";
$result = mysql_query($sql);
$totalPrice=0;
echo"<table width='75%' border='1' bordercolor='#A59A1B' bgcolor='#D3BC38' ><tr align='center'><td><b>ภาพสินค้า</b></td>
<td><b>รหัสสินค้า</b></td>
<td><b>ชื่อสินค้า</b></td>
<td><b>ราคา</b></td>
<td><b>แก้ไขจำนวนสินค้า</b>
<td><b>แก้ไขสินค้า</b>
<td><b></b>
</td></tr>";
while($row=mysql_fetch_array($result)){
$ProductID = $row["proid"];
$productName = $row["name"];
$productPrice = $row["price"];
$productqty = $row["qty"];
$pic = $row["pic"];
echo "<tr bgcolor='#D3BC38' align='center'><form id='form1' name='form1' method='post' action='Editproduct.php'>";
echo"<td><img src='$pic' width=150 height=150 ></td>";
echo "<td>$ProductID<input name='proid' type='hidden' value='$ProductID'></td><td><input name='name' type='text' value='$productName'></td>";
echo "<td><input name='price' type='text' value='$productPrice'></td>";
echo "<td><input name='qty' type='text' value='$productqty'></td>";
echo "<td><input type='submit' name='Delete' id='Edit' value='Edit' onclick=" ?>"return confirm('คุณแน่ใจว่าต้องการแก้ไขข้อมูลนี้หรือไม่ ? ')" /><? "/>";
echo "</td></form></tr>";
}
echo "</table>";
?>
ผลคือ

อ่าผมพลาดตรงไหนหว่า
-----------------------------------------------------
อ้อลืมแนบอันนี้มาด้วยครับ
Code (PHP)
<?
header("Content-Type: text/html; charset=TIS-620");
session_start();
$sessionID= session_id();
$removeProductID = $_POST['ProductID'];
?>
เป็น code ที่อยู่บนสุดของหน้านี้ครับ ผมไม่เข้าใจการทำงานของ session_start(); เท่าไหร่ แต่เห็นว่าต้นฉบับมันมาแบบนี้ เลยคงไว้น่ะครับ ไม่รู้ว่าจะเกี่ยวของกันหรือเปล่า (เพราะหนังสือก็ไม่ได้มีอธิบายตรงส่วนนี้ อยู่ๆก็โผล่มาโต้งๆเลย งง)
|
ประวัติการแก้ไข 2011-11-23 06:06:23 2011-11-23 06:27:18
 |
 |
 |
 |
Date :
2011-11-23 06:04:38 |
By :
TopKisser |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองแก้ใขโดยการนำ if ที่ update ไปไว้ส่วนหลังจากแสดงผลแทนแบบนี้

ผลคือก็ยังไม่ได้เช่นกันครับ 
|
 |
 |
 |
 |
Date :
2011-11-23 06:10:31 |
By :
TopKisser |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
session_start(); เป็นการเรียกใช้ session เพื่อเช็คค่า (username,password,id ...etc) ที่เราล็อกอินและเก็บค่าไว้ที่ session
ไม่น่าจะเกี่ยวกับตรงที่ update db เพราะล็อกอินมาถึงหน้าแก้ไขได้แล้ว
ตรงที่ต้องไปเช็ค ก็คือ ค่าตัวแปรทั้งหลาย ที่รับมาจาก $_POST นั่นแหละที่มันไม่มีอะไรส่งมา มันก็เลย อัพเดทไม่ได้
ลองไล่ดูดีๆ
|
 |
 |
 |
 |
Date :
2011-11-23 06:34:09 |
By :
nimporn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

ค่ามันมีค่าส่งมา ก็ควรจะเป็นแบบนี้
เราลงใช้ไฟล์อัพเดทตามข้างล่างนี้นะ
Code (PHP)
<?php
$ProductID=$_POST['ProductID'];
$qty=$_POST['qty'];
$Pprice=$_POST['Pprice'];
$Pname=$_POST['Pname'];
echo "ProductID= ",$ProductID;
echo "<br>qty= ",$qty;
echo "<br>Pprice= ",$Pprice;
echo "<br>Pname= ",$Pname;
if ($ProductID>0){
$sql = "UPDATE product
SET name = '$Pname',
price = '$Pprice',
qty = '$qty'
WHERE proid ='$ProductID' ;";
mysql_query($sql);
}
$sql = "SELECT * FROM product";
$result = mysql_query($sql);
$totalPrice=0;
echo"<table width='75%' border='1' bordercolor='#A59A1B' bgcolor='#D3BC38' ><tr align='center'><td><b>ภาพสินค้า</b></td>
<td> <b>รหัสสินค้า</b></td>
<td> <b>ชื่อสินค้า</b></td>
<td><b>ราคา</b></td>
<td><b>แก้ไขจำนวนสินค้า</b>
<td><b>แก้ไขสินค้า</b>
<td><b></b>
</td></tr>";
while($row=mysql_fetch_array($result)){
$ProductID = $row["proid"];
$productName = $row["name"];
$productPrice = $row["price"];
$productqty = $row["qty"];
$pic = $row["pic"];
echo "<tr bgcolor='#D3BC38' align='center'><form id='form1' name='form1' method='post' action='editerror.php'>";
echo"<td><img src='$pic' width=150 height=150 ></td>";
echo "<td>$ProductID<input name='ProductID' type='hidden' value='$ProductID'></td><td><input name='Pname' type='text' value='$productName'></td>";
echo "<td><input name='Pprice' type='text' value='$productPrice'></td>";
echo "<td><input name='qty' type='text' value='$productqty'></td>";
echo "<td><input type='submit' name='Delete' id='Edit' value='Edit' onclick=" ?>"return confirm('คุณแน่ใจว่าต้องการแก้ไขข้อมูลนี้หรือไม่ ? ')" /><? "/>";
echo "</td></form></tr>";
}
echo "</table>";
?>
</br></td>
<td></td>
</tr>
<tr>
<td height="29" ></td>
<td rowspan="2">
<h3 align="left"> </h3></td>
<td></td>
</tr>
<tr>
</tr>
</table>
</body>
</html>
|
 |
 |
 |
 |
Date :
2011-11-23 06:39:40 |
By :
nimporn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองเอา code ของคุณ nimporn ข้างบนนี้ไปลองใช้ดู ผลคือมันออกแบบนี้อะครับ

ส่วนอันนี้คือบรรทัดที่มันแจ้งว่ามีปัญหา

ผมลองเชคดูมันก็ code ก็เหมือนของคุณ nimporn น้า แต่ทำไมมันเป็นแบบนี้หว่า
|
ประวัติการแก้ไข 2011-11-23 06:59:21
 |
 |
 |
 |
Date :
2011-11-23 06:58:50 |
By :
TopKisser |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้เป็น code แบบเต็มๆหน้า ของหน้านี้ครับ ผมแนบไว้ละกัน เผื่อผมผิดในจุดอื่น
Code (PHP)
<?
header("Content-Type: text/html; charset=TIS-620");
session_start();
$sessionID= session_id();
$removeProductID = $_POST['ProductID'];
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-color: #FFFFFF;
}
-->
</style>
<script type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<table width="1008" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="134" rowspan="2" valign="top"><img src="./pic/Ntopleft.gif" width="134" height="142" /></td>
<td height="97" colspan="2" valign="top"><img src="./pic/Ntopleft2.gif" alt="" width="56" height="97" /><a href="Addproduct.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image10','','pic/mbook1.gif',1)"><img src="pic/mbook.gif" alt="" name="Image10" width="113" height="96" border="0" id="Image10" /></a><a href="Editproduct.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image11','','pic/mMaster1.gif',1)"><img src="pic/mMaster1.gif" alt="" name="Image11" width="94" height="97" border="0" id="Image11" /></a><a href="Removeproduct.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image12','','pic/mReport1.gif',1)"><img src="pic/mReport.gif" alt="" name="Image12" width="118" height="97" border="0" id="Image12" /></a><img src="./pic/topmid2.gif" alt="" width="277" height="97" /></td>
<td width="100"> </td>
</tr>
<tr>
<td width="4" height="36"> </td>
<td width="770" rowspan="2" valign="top"><p><img src="./pic/mid12.jpg" width="115" height="64" /><img src="./pic/mid2.jpg" width="110" height="66" /><img src="./pic/mid2.jpg" width="110" height="66" /><img src="./pic/mid2.jpg" width="104" height="66" /><img src="./pic/mid2.jpg" width="103" height="66" /><img src="./pic/mid3.jpg" width="116" height="66" /></p></td>
<td> </td>
</tr>
<tr>
<td rowspan="3" valign="top" ><!--DWLayoutEmptyCell--> </td>
<td height="30"></td>
<td></td>
</tr>
<tr>
<td height="26"></td>
<td><br>
<?php
$ProductID=$_POST['ProductID'];
$qty=$_POST['qty'];
$Pprice=$_POST['Pprice'];
$Pname=$_POST['Pname'];
echo "ProductID= ",$ProductID;
echo "<br>qty= ",$qty;
echo "<br>Pprice= ",$Pprice;
echo "<br>Pname= ",$Pname;
if ($ProductID>0){
$sql = "UPDATE product
SET name = '$Pname',
price = '$Pprice',
qty = '$qty'
WHERE proid ='$ProductID' ;";
mysql_query($sql);
}
$sql = "SELECT * FROM product";
$result = mysql_query($sql);
$totalPrice=0;
echo"<table width='75%' border='1' bordercolor='#A59A1B' bgcolor='#D3BC38' ><tr align='center'><td><b>ภาพสินค้า</b></td>
<td> <b>รหัสสินค้า</b></td>
<td> <b>ชื่อสินค้า</b></td>
<td><b>ราคา</b></td>
<td><b>แก้ไขจำนวนสินค้า</b>
<td><b>แก้ไขสินค้า</b>
<td><b></b>
</td></tr>";
while($row=mysql_fetch_array($result)){
$ProductID = $row["proid"];
$productName = $row["name"];
$productPrice = $row["price"];
$productqty = $row["qty"];
$pic = $row["pic"];
echo "<tr bgcolor='#D3BC38' align='center'><form id='form1' name='form1' method='post' action='editerror.php'>";
echo"<td><img src='$pic' width=150 height=150 ></td>";
echo "<td>$ProductID<input name='ProductID' type='hidden' value='$ProductID'></td><td><input name='Pname' type='text' value='$productName'></td>";
echo "<td><input name='Pprice' type='text' value='$productPrice'></td>";
echo "<td><input name='qty' type='text' value='$productqty'></td>";
echo "<td><input type='submit' name='Delete' id='Edit' value='Edit' onclick=" ?>"return confirm('คุณแน่ใจว่าต้องการแก้ไขข้อมูลนี้หรือไม่ ? ')" /><? "/>";
echo "</td></form></tr>";
}
echo "</table>";
?>
</br></td>
<td></td>
</tr>
<tr>
<td height="29" ></td>
<td rowspan="2">
<h3 align="left"> </h3></td>
<td></td>
</tr>
<tr>
</tr>
</table>
</body>
</html>
|
 |
 |
 |
 |
Date :
2011-11-23 07:00:36 |
By :
TopKisser |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
code เต็มๆ แล้ว include ("config.inc.php"); มันหายไปไหน เอามาใส่คืนด้วย
ในโค้ดของเราไม่มีให้เห็น เพราะละเอาไว้น่ะ
|
 |
 |
 |
 |
Date :
2011-11-23 08:13:15 |
By :
nimporn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แบบนี้ใช่ไหมครับ
Code (PHP)
<?php
include ("config.inc.php");
$ProductID=$_POST['ProductID'];
$qty=$_POST['qty'];
$Pprice=$_POST['Pprice'];
$Pname=$_POST['Pname'];
echo "ProductID= ",$ProductID;
echo "<br>qty= ",$qty;
echo "<br>Pprice= ",$Pprice;
echo "<br>Pname= ",$Pname;
if ($ProductID>0){
$sql = "UPDATE product
SET name = '$Pname',
price = '$Pprice',
qty = '$qty'
WHERE proid ='$ProductID' ;";
mysql_query($sql);
}
$sql = "SELECT * FROM product";
$result = mysql_query($sql);
$totalPrice=0;
echo"<table width='75%' border='1' bordercolor='#A59A1B' bgcolor='#D3BC38' ><tr align='center'><td><b>ภาพสินค้า</b></td>
<td> <b>รหัสสินค้า</b></td>
<td> <b>ชื่อสินค้า</b></td>
<td><b>ราคา</b></td>
<td><b>แก้ไขจำนวนสินค้า</b>
<td><b>แก้ไขสินค้า</b>
<td><b></b>
</td></tr>";
while($row=mysql_fetch_array($result)){
$ProductID = $row["proid"];
$productName = $row["name"];
$productPrice = $row["price"];
$productqty = $row["qty"];
$pic = $row["pic"];
echo "<tr bgcolor='#D3BC38' align='center'><form id='form1' name='form1' method='post' action='editerror.php'>";
echo"<td><img src='$pic' width=150 height=150 ></td>";
echo "<td>$ProductID<input name='ProductID' type='hidden' value='$ProductID'></td><td><input name='Pname' type='text' value='$productName'></td>";
echo "<td><input name='Pprice' type='text' value='$productPrice'></td>";
echo "<td><input name='qty' type='text' value='$productqty'></td>";
echo "<td><input type='submit' name='Delete' id='Edit' value='Edit' onclick=" ?>"return confirm('คุณแน่ใจว่าต้องการแก้ไขข้อมูลนี้หรือไม่ ? ')" /><? "/>";
echo "</td></form></tr>";
}
echo "</table>";
?>
</br></td>
<td></td>
</tr>
<tr>
<td height="29" ></td>
<td rowspan="2">
<h3 align="left"> </h3></td>
<td></td>
</tr>
<tr>
</tr>
</table>
</body>
</html>
ทดลองรันแล้ว รันได้ละครับ แต่ว่ามันยังไม่มีค่าเช่นเดิม

พอลองกด edit ดูขึ้นหน้า error แบบนี้เลย

T_T
|
 |
 |
 |
 |
Date :
2011-11-23 08:35:17 |
By :
TopKisser |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ชื่อไฟล์ editerror.php ในฟอร์ม ให้เป็นชื่อไฟล์ที่คุณใช้ด้วยน่ะ
รู้สึกจะเป็น Editproduct.php
โทษที เพราะเอาไปลองทำ ไม่ได้ตั้งชื่อไฟล์ให้หมือนกัน
|
ประวัติการแก้ไข 2011-11-23 08:39:51
 |
 |
 |
 |
Date :
2011-11-23 08:38:28 |
By :
nimporn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ้อได้ละครับ ขอบคุณมากๆ ผมก็ลืมสังเกตุไป มัวแต่โฟสกัสอยู่ที่ if
ตอนนี้รันผ่านละครับ ขอบคุณอีกครั้ง

|
 |
 |
 |
 |
Date :
2011-11-23 08:46:00 |
By :
TopKisser |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|