|
 |
|
ช่วยหน่อยนะค่า ผิดตรงไหนไม่รุ TT ,, เพิ่ม แก้ไข ข้อมูลไม่ได้ ลบได้อย่างเดียว |
|
 |
|
|
 |
 |
|
แก้ไข , เพ่ิม ข้อมูลไม่ได้คะ ผิดตรงไหน ??? ช่วยดูหน่อยนะค่า Plz++
store_promotion.php
<?
$objConnect = mysql_connect("localhost","root","admin") or die("Error Connect to Database");
$objDB = mysql_select_db("homemall");
//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
$strSQL = "INSERT INTO promotioninfo";
$strSQL .="(IDPromotion,IDProType,PicPromotion,DatePromotion) ";
$strSQL .="VALUES";
$strSQL .="('".$_POST["txtAddIDPromotion"]."','".$_POST["txtAddIDProType"]."' ";
$strSQL .=",'".$_POST["txtAddPicPromotion"]."' ";
$strSQL .=",NOW()) ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Save [".mysql_error()."]";
}
}
//*** Update Condition ***//
if($_POST["hdnCmd"] == "Update")
{
$strSQL = "UPDATE promotioninfo SET ";
$strSQL .="IDPromotion = '".$_POST["txtEditIDPromotion"]."' ";
$strSQL .=",IDProType = '".$_POST["txtEditIDProType"]."' ";
$strSQL .=",PicPromotion = '".$_POST["txtEditPicPromotion"]."' ";
$strSQL .=",DatePromotion = NOW() ";
$strSQL .="WHERE IDPromotion = '".$_POST["hdnEditIDPromotion"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Update [".mysql_error()."]";
}
}
//*** Delete Condition ***//
if($_GET["Action"] == "Del")
{
$strSQL = "DELETE FROM promotioninfo ";
$strSQL .="WHERE IDPromotion = '".$_GET["IDPromotion"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Delete [".mysql_error()."]";
}
}
$strSQL = "SELECT * FROM promotioninfo";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form action="<?=$_SERVER["PHP_SELF"];?>" method="post">
<input type="hidden" name="hdnCmd" value="">
<table width="900" border="1">
<tr>
<th width="10">No.</th>
<th width="10">ประเภทโปรโมชั่น</th>
<th width="100">รูปสินค้า</th>
<th width="50">วันที่อัพโหลด</th>
<th width="20">Edit</th>
<th width="20">Delete</th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
if($objResult["IDPromotion"] == $_GET["IDPromotion"] and $_GET["Action"] == "Edit")
{
?>
<tr>
<td>
<input type="text" name="txtEditIDPromotion" size="5" value="<?=$objResult["IDPromotion"];?>">
</td>
<td>
<select name="txtEditIDProType" id="select" value="<?=$objResult["IDProType"];?>">
<option>สินค้ามาใหม่</option>
<option>โปรโมชั่นในร้าน</option>
<option>โปรโมชั่นรายเดือน</option>
<option>ดาวน์โหลดแคตตาล็อค</option>
</select>
</td>
<td>
<input type="file" name="txtEditPicPromotion" size="20" value="<?=$objResult["PicPromotion"];?>">
</td>
<td>
<td>
<input type="text" name="txtEditDatePromotion" size="20" value="<?=$objResult["DatePromotion"];?>">
</td>
<td colspan="2" align="right">
<div align="center">
<input name="btnAdd" type="image" id="btnUpdate" src="image/tick.png" width="28" height="28" OnClick=
"frmMain.hdnCmd.value='Update';frmMain.submit();">
<input name="btnAdd" type="image" id="btnCancel" src="image/delete.png" width="28" height="28" OnClick="window.location='<?=$_SERVER["PHP_SELF"];
?>';">
</div></td>
</tr>
<?
}
else{
?>
<tr>
<td><?=$objResult["IDPromotion"];?></td>
<td><?=$objResult["IDProType"];?></td>
<td><?=$objResult["PicPromotion"];?></td>
<td><?=$objResult["DatePromotion"];?></td>
<td><a href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&IDPromotion=<?=$objResult["IDPromotion"];?>">Edit</a></td>
<td><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&IDPromotion=<?=
$objResult["IDPromotion"];?>';}">Delete</a></td>
</tr>
<?
}
}
?>
<tr>
<td><input type="text" name="txtAddIDPromotion" size="5" readonly></td>
<td><input type="text" name="txtAddIDProType" size="5"></td>
<td><input type="text" name="txtAddPicPromotion" size="20"></td>
<td><input type="text" name="txtAddDatePromotion" size="5" readonly></td>
<td colspan="2" align="right">
<div align="center">
<input name="btnAdd" type="image" id="btnAdd" src="image/add.png" width="28" height="28" OnClick="frmMain.hdnCmd.value='Add';frmMain.submit();">
</div></td>
</tr>
</table>
</form>
<?
mysql_close($objConnect);
?>
</body>
</html>
Tag : PHP

|
ประวัติการแก้ไข 2011-11-12 15:53:14
|
 |
 |
 |
 |
Date :
2011-11-12 14:36:45 |
By :
Poster |
View :
1238 |
Reply :
6 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขออภัยสำหรับคำตอบนะครับ.....
1. คือผมไม่มีฐานข้อมูลแบบนี้เลยไม่รู้ว่าจะเอาไปทดลองยังไง.....
2. ไม่ทราบว่าปัญหานี้มี error message มั้ยครับ.....
|
 |
 |
 |
 |
Date :
2011-11-12 14:58:56 |
By :
Songkram |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
CREATE TABLE `promotioninfo` (
`IDPromotion` int(255) NOT NULL auto_increment,
`PicPromotion` varchar(1000) collate utf8_bin NOT NULL,
`Brand` varchar(1000) collate utf8_bin NOT NULL,
`Generation` varchar(500) collate utf8_bin NOT NULL,
`NamePromotion` varchar(500) collate utf8_bin NOT NULL,
`IDProType` varchar(1) collate utf8_bin NOT NULL,
`DatePromotion` datetime NOT NULL,
PRIMARY KEY (`IDPromotion`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=3 ;
ไม่มี error message คะ แต่เพิ่มและแก้ไข ข้อมูลไม่ได้คะ ลบได้อย่างเดียวคะคะ
ขอบคุนมากนะคะ
|
ประวัติการแก้ไข 2011-11-12 15:52:13
 |
 |
 |
 |
Date :
2011-11-12 15:51:51 |
By :
Poster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมว่ามันไม่รู้จักคำนี้ครับ "frmMain.hdnCmd.value"
ลองเพิ่มชื่อให้กับ form ดูนะครับ.....บันทัดที่ 53
จาก Code (PHP)
<form action="<?=$_SERVER["PHP_SELF"];?>" method="post">
เป็นดังนี้
Code (PHP)
<form name="frmMain" action="<?=$_SERVER["PHP_SELF"];?>" method="post">
การที่มันไม่สามารถอัพเดตหรือเพิ่มข้อมูลได้เพราะมันไม่สามารถใส่ value ใน input ที่ชื่อว่า "hdnCmd" ได้ครับ มีหลายวิธีที่จะเซตค่าให้กับมัน แต่ถ้าใช้วิธีนี้ (ของ จขกท) ก็ลองเพิ่มชื่อฟอร์มตามที่ผมแนะนำดูก่อนก็ได้ครับ.... แต่ถ้ายังไม่ได้เดี๋ยวมีวิธีอื่นอีกครับ....
|
 |
 |
 |
 |
Date :
2011-11-12 16:07:39 |
By :
Songkram |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองแล้วนะคะ ยังไม่ได้เลยคะ TT
store_promotion.php
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<title>Add Edit Delete Promotion & New Promotion</title>
<style type="text/css">
body{font-family: verdana, geneva, sans-serif;}
table{border: 1px solid #aaa7a2;-moz-border-radius: 5px 5px 5px 5px;} /* กำหนดสีเส้นขอบตาราง*/
th{background-color:#4c8459;border: 0px;padding:6px;color: #ffffff; font: 13px Verdana } /* กำหนดสีเส้นขอบตาราง*/
td {border: 0px ;background-color:#f7f4ef;padding:3px;color: black; font: 13px Verdana}
a:link{text-decoration:none;color:#5e8882}
a:visited{text-decoration:none;color:#5e8882}
a:active{text-decoration:none;color:#5e8882}
a:hover{text-decoration:none; color:#20a6c3}
</style>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","admin") or die("Error Connect to Database");
$objDB = mysql_select_db("homemall");
//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
$strSQL = "INSERT INTO promotioninfo";
$strSQL .="(IDPromotion,IDProType,PicPromotion,DatePromotion) ";
$strSQL .="VALUES";
$strSQL .="('".$_POST["txtAddIDPromotion"]."','".$_POST["txtAddIDProType"]."' ";
$strSQL .=",'".$_POST["txtAddPicPromotion"]."' ";
$strSQL .=",NOW()) ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Save [".mysql_error()."]";
}
}
//*** Update Condition ***//
if($_POST["hdnCmd"] == "Update")
{
$strSQL = "UPDATE promotioninfo SET ";
$strSQL .="IDPromotion = '".$_POST["txtEditIDPromotion"]."' ";
$strSQL .=",IDProType = '".$_POST["txtEditIDProType"]."' ";
$strSQL .=",PicPromotion = '".$_POST["txtEditPicPromotion"]."' ";
$strSQL .=",DatePromotion = NOW() ";
$strSQL .="WHERE IDPromotion = '".$_POST["hdnEditIDPromotion"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Update [".mysql_error()."]";
}
}
//*** Delete Condition ***//
if($_GET["Action"] == "Del")
{
$strSQL = "DELETE FROM promotioninfo ";
$strSQL .="WHERE IDPromotion = '".$_GET["IDPromotion"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Delete [".mysql_error()."]";
}
}
$strSQL = "SELECT * FROM promotioninfo";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form name="frmMain" action="<?=$_SERVER["PHP_SELF"];?>" method="post">
<input type="hidden" name="hdnCmd" value="">
<table width="900" border="1">
<tr>
<th width="10">No.</th>
<th width="10">ประเภทโปรโมชั่น</th>
<th width="100">รูปสินค้า</th>
<th width="50">วันที่อัพโหลด</th>
<th width="20">Edit</th>
<th width="20">Delete</th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
if($objResult["IDPromotion"] == $_GET["IDPromotion"] and $_GET["Action"] == "Edit")
{
?>
<tr>
<td>
<input type="text" name="txtEditIDPromotion" size="5" value="<?=$objResult["IDPromotion"];?>">
</td>
<td>
<select name="txtEditIDProType" id="select" value="<?=$objResult["IDProType"];?>">
<option>สินค้ามาใหม่</option>
<option>โปรโมชั่นในร้าน</option>
<option>โปรโมชั่นรายเดือน</option>
<option>ดาวน์โหลดแคตตาล็อค</option>
</select>
</td>
<td>
<input type="file" name="txtEditPicPromotion" size="20" value="<?=$objResult["PicPromotion"];?>">
</td>
<td>
<td>
<input type="text" name="txtEditDatePromotion" size="20" value="<?=$objResult["DatePromotion"];?>">
</td>
<td colspan="2" align="right">
<div align="center">
<input name="btnAdd" type="image" id="btnUpdate" src="image/tick.png" width="28" height="28" OnClick=
"frmMain.hdnCmd.value='Update';frmMain.submit();">
<input name="btnAdd" type="image" id="btnCancel" src="image/delete.png" width="28" height="28" OnClick="window.location='<?=$_SERVER["PHP_SELF"];
?>';">
</div></td>
</tr>
<?
}
else{
?>
<tr>
<td><?=$objResult["IDPromotion"];?></td>
<td><?=$objResult["IDProType"];?></td>
<td><?=$objResult["PicPromotion"];?></td>
<td><?=$objResult["DatePromotion"];?></td>
<td><a href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&IDPromotion=<?=$objResult["IDPromotion"];?>">Edit</a></td>
<td><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&IDPromotion=<?=
$objResult["IDPromotion"];?>';}">Delete</a></td>
</tr>
<?
}
}
?>
<tr>
<td><input type="text" name="txtAddIDPromotion" size="5" readonly></td>
<td><input type="text" name="txtAddIDProType" size="5"></td>
<td><input type="text" name="txtAddPicPromotion" size="20"></td>
<td><input type="text" name="txtAddDatePromotion" size="5" readonly></td>
<td colspan="2" align="right">
<div align="center">
<input name="btnAdd" type="image" id="btnAdd" src="image/add.png" width="28" height="28" OnClick="frmMain.hdnCmd.value='Add';frmMain.submit();">
</div></td>
</tr>
</table>
</form>
<?
mysql_close($objConnect);
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2011-11-12 16:37:08 |
By :
Poster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ครับ ... มันมีปัญหาเดียวครับ แต่สองที่ คือ
บันทัดที่ 109 ตรงคำสั่ง OnClick="frmMain.hdnCmd.value='Update';frmMain.submit();"
กับบันทัดที่ 140 ตรงคำสั่ง OnClick="frmMain.hdnCmd.value='Add';frmMain.submit();"
ซึ่งสองคำสั่งนี้ frmMain.hdnCmd.value='Update' กับ frmMain.hdnCmd.value='Add' พยายามใส่ค่าให้กับ Input ที่ชื่อว่า "hdnCmd"
.............................
ขั้นแรกของบันทัด 70 ลองเปลี่ยน type="hidden" เป็น type="text"
แล้วที่บันทัด 140 ให้เอา frmMain.submit() ออกก่อน แล้วกดปุ่มเพื่อเพิ่มข้อมูล เพื่อดูว่า input ที่ชื่อว่า "hdnCmd" ได้ค่า "Add" เข้าไปหรือไม่.......
ถ้าในช่อง input ที่ชื่อว่า "hdnCmd" มีค่า "Add" ปรากฎขึ้นมาก็แสดงว่าบันทัด 140 ใช้งานได้
ให้ลองทำแบบเดียวกันตรงบันทัด 70 เพื่อตรวจสอบดูว่าใช้งานได้เหมือนกีนหรือไม่.....
การตรวจสอบตรงนี้เพื่อให้แน่ใจว่าในช่อง Input ที่ชื่อว่า "hdnCmd" มีค่าที่ถูกต้องก่อน Submit
ถ้าตรวสอบแล้วใม่ขึ้นตามความต้องการให้ลองทำดังนี้ครับ
1. เปลี่ยน "frmMain.hdnCmd.value='Add';frmMain.submit();" เป็น
Code (PHP)
"document.getElementById('hdnCmd').value='Add';document.forms['hdnCmd'].submit();"
2. เปลี่ยน "frmMain.hdnCmd.value='Update';frmMain.submit();" เป็น
Code (PHP)
"document.getElementById('hdnCmd').value='Update';document.forms['hdnCmd'].submit();"
......................................
ลองแค่นี้ดูก่อนละกันครับ ติด error ตรงไหนต่อก็โพสมาโลด
|
 |
 |
 |
 |
Date :
2011-11-12 16:59:14 |
By :
Songkram |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เพิ่มได้แล้วคะ แต่แก้ไขยังไม่ได้คะ
Code (PHP)
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<title>Add Edit Delete New Promotion</title>
<style type="text/css">
body{font-family: verdana, geneva, sans-serif;}
table{border: 1px solid #aaa7a2;-moz-border-radius: 5px 5px 5px 5px;} /* กำหนดสีเส้นขอบตาราง*/
th{background-color:#4c8459;border: 0px;padding:6px;color: #ffffff; font: 13px Verdana } /* กำหนดสีเส้นขอบตาราง*/
td {border: 0px ;background-color:#f7f4ef;padding:3px;color: black; font: 13px Verdana}
a:link{text-decoration:none;color:#5e8882}
a:visited{text-decoration:none;color:#5e8882}
a:active{text-decoration:none;color:#5e8882}
a:hover{text-decoration:none; color:#20a6c3}
</style>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","admin") or die("Error Connect to Database");
$objDB = mysql_select_db("homemall");
//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
$strSQL = "INSERT INTO promotioninfo";
$strSQL .="(IDPromotion,IDProType,PicPromotion,DatePromotion) ";
$strSQL .="VALUES";
$strSQL .="('".$_POST["txtAddIDPromotion"]."','".$_POST["txtAddIDProType"]."' ";
$strSQL .=",'".$_POST["txtAddPicPromotion"]."' ";
$strSQL .=",NOW()) ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Save [".mysql_error()."]";
}
}
//*** Update Condition ***//
if($_POST["hdnCmd"] == "Update")
{
$strSQL = "UPDATE promotioninfo SET ";
$strSQL .="IDPromotion = '".$_POST["txtEditIDPromotion"]."' ";
$strSQL .=",IDProType = '".$_POST["txtEditIDProType"]."' ";
$strSQL .=",PicPromotion = '".$_POST["txtEditPicPromotion"]."' ";
$strSQL .=",DatePromotion = NOW() ";
$strSQL .="WHERE IDPromotion = '".$_POST["hdnEditIDPromotion"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Update [".mysql_error()."]";
}
}
//*** Delete Condition ***//
if($_GET["Action"] == "Del")
{
$strSQL = "DELETE FROM promotioninfo ";
$strSQL .="WHERE IDPromotion = '".$_GET["IDPromotion"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Delete [".mysql_error()."]";
}
}
$strSQL = "SELECT `promotioninfo`. * , `protype`.`NameProType`
FROM `promotioninfo` , `protype`
WHERE `promotioninfo`.`IDProType` = `protype`.`IDProType` ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form name="frmMain" action="<?=$_SERVER["PHP_SELF"];?>" method="post">
<input type="hidden" name="hdnCmd" value="">
<table width="900" border="1">
<tr>
<th width="10">No.</th>
<th width="10">ประเภทโปรโมชั่น</th>
<th width="100">รูปโปรโมชั่น</th>
<th width="50">วันที่อัพโหลด</th>
<th width="20">Edit</th>
<th width="20">Delete</th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
if($objResult["IDPromotion"] == $_GET["IDPromotion"] and $_GET["Action"] == "Edit")
{
?>
<tr>
<td>
<input type="text" name="txtEditIDPromotion" size="5" value="<?=$objResult["IDPromotion"];?>">
</td>
<td>
<select name="txtEditIDProType" id="select" value="<?=$objResult["IDProType"];?>">
<option>สินค้ามาใหม่</option>
<option>โปรโมชั่นในร้าน</option>
<option>โปรโมชั่นรายเดือน</option>
<option>ดาวน์โหลดแคตตาล็อค</option>
</select>
</td>
<td>
<input type="file" name="txtEditPicPromotion" size="20" value="<?=$objResult["PicPromotion"];?>">
</td>
<td>
<td>
<input type="text" name="txtEditDatePromotion" size="20" value="<?=$objResult["DatePromotion"];?>">
</td>
<td colspan="2" align="right">
<div align="center">
<input name="btnAdd" type="image" id="btnUpdate" src="image/tick.png" width="28" height="28" OnClick=
"document.getElementById('hdnCmd').value='Update';document.forms['hdnCmd'].submit();">
<input name="btnAdd" type="image" id="btnCancel" src="image/delete.png" width="28" height="28" OnClick="window.location='<?=$_SERVER["PHP_SELF"];
?>';">
</div></td>
</tr>
<?
}
else{
?>
<tr>
<td><?=$objResult["IDPromotion"];?></td>
<td><?=$objResult["NameProType"];?></td>
<td><img src="<?="../../".$objResult["PicPromotion"];?>" width="100" height="100"></td>
<td><?=$objResult["DatePromotion"];?></td>
<td><a href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&IDPromotion=<?=$objResult["IDPromotion"];?>">Edit</a></td>
<td><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&IDPromotion=<?=
$objResult["IDPromotion"];?>';}">Delete</a></td>
</tr>
<?
}
}
?>
<tr>
<td><input type="text" name="txtAddIDPromotion" size="5" readonly></td>
<td>
<select name="txtAddIDProType" id="select" value="<?=$objResult["IDProType"];?>">
<option>สินค้ามาใหม่</option>
<option>โปรโมชั่นในร้าน</option>
<option>โปรโมชั่นรายเดือน</option>
<option>ดาวน์โหลดแคตตาล็อค</option>
</select>
</td>
<td><input type="file" name="txtAddPicPromotion" size="20"></td>
<td><input type="text" name="txtAddDatePromotion" size="5" readonly></td>
<td colspan="2" align="right">
<div align="center">
<input name="btnAdd" type="image" id="btnAdd" src="image/add.png" width="28" height="28" OnClick="frmMain.hdnCmd.value='Add';">
</div></td>
</tr>
</table>
</form>
<?
mysql_close($objConnect);
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2011-11-12 22:05:43 |
By :
Poster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|