|
|
|
ช่วยหน่อยครับ ส่ง ค่าไป แล้ว มันบันทึกไม่ได้ ครับ มันเป็นไรครับ แก้ไม่ได้ ระบบขายสินค้าออนไลน์ |
|
|
|
|
|
|
|
หน้า product_ad จะส่งค่าไป insert_ad
นี่คือหน้า product_ad
Code (PHP)
<?
include("headder.php");
require("javachkbox.html");
?>
<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<style type="text/css">
<!--
.style1 {
font-family: tahoma;
font-size: 12px;
color: #FF0000;
font-weight: bold;
}
.style2 {
color: #FFFFFF;
font-weight: bold;
}
.style3 {color: #FFFFFF}
.style4 {color: #FF0000}
.style5 {color: #CC6600}
body {
background-image: url(lopoo/b230.gif);
}
.style6 {
color: #0033FF;
font-weight: bold;
font-size: 24px;
font-family: Jokerman;
}
body,td,th {
color: #0033CC;
}
-->
</style>
<p class="style5"><span class="style6">ระบบจัดการสินค้า</span> <a href="index.php">กลับไปยังหน้า admin</a></p>
<form action="product_ad.php" name="form1">
<select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
<option value="">เลือกประเภท</option>
<?
$sqlda = "select * from tbl_category ";
$result = mysql_query( $sqlda );
while($regis = mysql_fetch_array( $result )){
echo "<option value=\"product_ad.php?cat_id=$regis[cat_id]\">$regis[cat_name]</option>";
}
?>
</select>
</form>
<form name="mylist" method="post" action="delete_product.php?cat_id=<? echo "$cat_id"; ?>">
<? echo "<input type=checkbox name='allchk' onClick=\"CheckAll()\"><font color='green'><b><u>เลือกทั้งหมด</u></b>";?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
<tr>
<td width="10%" align="center" valign="middle" bgcolor="#993300"><span class="style3">รหัสสินค้า</span></td>
<td width="17%" align="left" valign="middle" bgcolor="#993300"><span class="style3">หมวดสินค้า</span></td>
<td width="30%" align="left" valign="middle" bgcolor="#993300"><span class="style3">ชื่อสินค้า</span></td>
<td width="22%" align="left" valign="middle" bgcolor="#993300"><span class="style3">รายละเอียด</span></td>
<td width="13%" align="left" valign="middle" bgcolor="#993300"><span class="style3">จำนวน</span></td>
<td width="13%" align="left" valign="middle" bgcolor="#993300"><span class="style3">ราคา</span></td>
</tr>
<?
$pagelen = 8 ;
$page = $_REQUEST['page'];
if (empty($page)) { $page=1; }
mysql_connect($dbserver, $dbuser, $dbpass) or die("เชื่อมต่อฐานข้อมูลไม่ได้");
mysql_query("set NAMES tis620 ");
mysql_select_db($dbname) or die("เลือกฐานข้อมูลไม่ได้"); // เลือกฐานข้อมูล
$sql = "SELECT pd_id from tbl_product ";
$result = mysql_query( $sql );
$num_rows = mysql_num_rows($result);
$totalpage = ceil($num_rows / $pagelen);
$goto = ($page-1) * $pagelen;
$sql = "SELECT p.pd_id,c.cat_name,p.pd_name,p.pd_description,p.pd_qty,p.price from tbl_product as p,tbl_category as c where p.cat_id=c.cat_id and p.cat_id= '$cat_id' LIMIT $goto , $pagelen ";
$result = mysql_query( $sql );
$num_rows = mysql_num_rows($result);
For ($i=0; $i < $num_rows; $i++) {
$fetcharr = mysql_fetch_array($result);
$id = $fetcharr['pd_id'];
$newid = $id+1;
$cat = $fetcharr['cat_name'];
$name = $fetcharr['pd_name'];
$descipt = $fetcharr['pd_description'];
$pd_qty = $fetcharr['pd_qty'];
$price = $fetcharr['price'];
?>
<tr>
<td align="left" valign="middle"><? echo "<input type=checkbox name='$id' onclick=CCA(this) ><a href='javascript:void(0);' NAME='Picture' title='ดูรูปภาพ' "."onClick=window.open('phpListBlob.php?pd_id=$id','wn','width=330,height=350,".
"left=50,top=50,toolbar=0,status=0,resizable=1,scrollbars=1');>$id</a>"; ?></td>
<td align="left" valign="middle"><? echo "$cat"; ?></td>
<td align="left" valign="middle"><img src="image/download.gif" width="25" height="30" /><? echo "<a href='edit_product.php?cat_id=$cat_id&pd_id=$id'>$name</a>"; ?></td>
<td align="left" valign="middle"><? echo "$descipt"; ?></td>
<td align="left" valign="middle"><? echo "$pd_qty"; ?></td>
<td align="left" valign="middle"><? echo "$price"; ?></td>
</tr>
<?
}
echo "</table>";
echo "<input name=\"image\" type=\"image\" onClick=\"return Conf(this)\" src=\"image/error.gif\" width=\"20\" height=\"20\" alt='ลบข้อมูลครับ'> <font color='red'><u>ทำการลบ</u></font><br>";
if ($page > 1) {
$back = $page - 1;
echo "<a href=$PHP_SELF?page=1&?cat_id=$cat_id>".
"<img src=image/first.gif border=0 align=absmiddle alt=First></a>\n";
echo "<a href=$PHP_SELF?page=". $back ."&cat_id=$cat_id>
<img src=image/previous.gif border=0 align=absmiddle alt=Previous></a>";
}
For ($i=1 ; $i<=$totalpage ; $i++) {
if ($i == $page ) {
echo " [<b><font size =+1 color=#990000>$i</font></b>] \n";
} else {
echo " <a href=$PHP_SELF?page=$i&cat_id=$cat_id>$i</a> \n";
}
}
if ($page < $totalpage) {
$next = $page +1;
echo "<a href=$PHP_SELF?page=".$next."&cat_id=$cat_id>
<img src=image/next.gif border=0 align=absmiddle alt=Next></a>";
echo " <a href=$PHP_SELF?page=".$totalpage."?cat_id=$cat_id><img src=image/last.gif border=0 align=absmiddle alt=Last></a> \n";
}
?>
<span class="style1">
<span class="style5">
<?
$sqlcat = "select * from tbl_category where cat_id='$cat_id' ";
$result3 = mysql_query( $sqlcat );
$cate = mysql_fetch_array( $result3 );
$type = $cate["cat_name"];
echo "<br>แสดงรายละเอียดของสินค้าในประเภท <b>$type</b>";
?>
</span></span>
</form>
<SCRIPT language=javascript>//เช็ค ล๊อคอิน
function check_login_data() {
var formObj = document.sub_la;
if( (formObj.pd_name.value == "" ) ) { alert("กรุณากรอกชื่อหัวข้อสินค้าด้วยนะค่ะ" ); formObj.pd_name.focus(); return false; }
if( (formObj.descrip.value == "" ) ) { alert("กรุณากรอกรายละเอียดสินค้าด้วยนะค่ะ" ); formObj.descrip.focus(); return false; }
if( (formObj.pd_qty.value == "" ) ) { alert("กรุณากรอกจำนวนสินค้าด้วยนะค่ะ" ); formObj.pd_qty.focus(); return false; }
if( (formObj.price.value == "" ) ) { alert("กรุณากรอกราคาสินค้าด้วยนะค่ะ" ); formObj.price.focus(); return false; }
if( (formObj.ImageFile.value == "" ) ) { alert("กรุณาเลือกรูปภาพสินค้าด้วยนะค่ะ" ); formObj.ImageFile.focus(); return false; }
else return true ;
}
</SCRIPT>
<form action="insert_product.php?cat_id=<? echo "$cat_id"; ?>" method="post" name="sub_la" id="sub_la" onsubmit="return check_login_data(this);" enctype="multipart/form-data">
<table width="579" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="22%" align="left" valign="middle" bgcolor="#FFCC99" scope="col"><span class="style2"><u>ทำการสินค้าใหม่</u></span></td>
<th width="22%" align="left" valign="middle" bgcolor="#FFCC99" scope="col"> </th>
<th width="56%" align="left" valign="middle" bgcolor="#FFCC99" scope="col"> </th>
<th width="0%" align="left" valign="middle" scope="col"> </th>
</tr>
<tr>
<th height="22" align="right" valign="middle" bgcolor="#fafafa" scope="row">รหัสสินค้า</th>
<td colspan="2" align="left" valign="middle" bgcolor="#fafafa"><label><strong>
<?
$sql2 = "select pd_id from tbl_product order by pd_id desc LIMIT 1";
$result2 = mysql_query( $sql2, $conn);
$data = mysql_fetch_array( $result2 );
$newid = $data["pd_id"];
$newid = $newid +1;
$newid = sprintf("%06d", $newid);
echo "$newid";
?>
</strong></label>
<input name="pd_id" type="hidden" id="pd_id" value="<? echo "$newid"; ?>">
<input name="cat_id" type="hidden" id="cat_id" value="<? echo "$cat_id"; ?>">
<input type="hidden" name="MAX_FILE_SIZE" value="500000"></td>
<td align="left" valign="middle"> </td>
</tr>
<tr>
<th height="30" align="right" valign="middle" bgcolor="#fafafa" scope="row">ชื่อหัวข้อ </th>
<td colspan="2" align="left" valign="middle" bgcolor="#fafafa"><label>
<input name="pd_name" type="text" id="pd_name" />
</label></td>
<td align="left" valign="middle"> </td>
</tr>
<tr>
<th height="22" align="right" valign="middle" bgcolor="#fafafa" scope="row">รายละเอียด</th>
<td colspan="2" align="left" valign="middle" bgcolor="#fafafa"><textarea name="descrip" id="descrip"></textarea></td>
<td align="left" valign="middle"> </td>
</tr>
<tr>
</tr>
<tr>
<th height="30" align="right" valign="middle" bgcolor="#fafafa" scope="row">จำนวน</th>
<td colspan="2" align="left" valign="middle" bgcolor="#fafafa"><input name="pd_qty" type="text" id="pd_qty" /></td>
<td align="left" valign="middle"> </td>
</tr>
<tr>
<th height="30" align="right" valign="middle" bgcolor="#fafafa" scope="row">ราคาต่อชิ้น</th>
<td colspan="2" align="left" valign="middle" bgcolor="#fafafa"><input name="price" type="text" id="price" /></td>
<td align="left" valign="middle"> </td>
</tr>
<tr>
<th height="30" align="right" valign="middle" bgcolor="#fafafa" scope="row">รูปภาพสินค้า</th>
<td colspan="2" align="left" valign="middle" bgcolor="#fafafa"><p>
<input type="file" name="ImageFile" size="40"><br />
<span class="style4"> ใช้รุปภาพประเภท Gif , Jpeg เมื่อบันทึกข้อมูลแล้วท่านไม่สามารถแก้ไขรูปภาพได้</span> </p>
</td>
<td align="left" valign="middle"> </td>
</tr>
<tr>
<th height="30" align="right" valign="middle" bgcolor="#fafafa" scope="row"> </th>
<td colspan="2" align="left" valign="middle" bgcolor="#fafafa"><input type="submit" name="Submit" value="ดำเนินการ" /></td>
<td align="left" valign="middle"> </td>
</tr>
</table>
</form>
<? include("bottom.php"); ?>
ส่วนหน้า insert_ad โดยหน้า insert_adจะมี headder.php
Code (PHP)
<?
include("headder.php");
$msg = "<center>";
$msg .= "<img src=\"image/download.gif\" border='0'/><br><br><br>";
$msg .= "<b>ทำการเพิ่มข้อมูลเรียบร้อยค่ะ !</b><br>";
$msg .= "<br><br><b>ชื่อสินค้า :</b> $pd_name<br><br><hr>";
$msg .= "<meta http-equiv='refresh' content='1; url=product_ad.php?cat_id=$cat_id'>";
$msg .= "</center>";
echo $sqlcheck = "select pd_name,pd_qty from tbl_product where pd_name = '$pd_name' ";
$result = mysql_query( $sqlcheck, $conn );
$total_result = mysql_fetch_row($result);
echo "$total_result";
$sqlcheck2 = "select pd_id,pd_name,pd_qty from tbl_product where pd_name = '$pd_name' ";
$result2 = mysql_query( $sqlcheck2 );
$result = mysql_query( $sqlcheck, $conn );
$sum = $data['pd_qty'];
$id = $data['pd_id'];
if($total>=1){
echo "<br><br>มีชื่อสินค้านี้อยู่ในฐานข้อมูลอยู่แล้ว คุณต้องการจะบันทึกหรือไม่ ";
echo " <a href='insert_product.php?action=1&pa_name=$pd_name&sum2=$sum&pd_qty=$pd_qty&pd_id=$id&cat_id=$cat_id'>ใช่</a> ";
echo " <a href='insert_product.php?action=2'>ไม่ใช่</a>";
exit();
}
if($action==1){
$pd_qty = $pd_qty+$sum2;
$sqlup = "update tbl_product set pd_qty='$pd_qty' where pd_id='$pd_id' ";
$result = mysql_query( $sqlup )or die("ไม่สามารถปรับปรุงข้อมูลได้");
echo "$msg";
exit();
}else if($action==2){
echo "<meta http-equiv='refresh' content='1; url=product_ad.php?cat_id=$cat_id'>";
exit();
}
if ( $ImageFile_type == "image/gif" or $ImageFile_type == "image/pjpeg")
{
$ImageFile = addslashes( fread( fopen( $ImageFile, "r" ), filesize( $ImageFile ) ) );
$strSQL = "INSERT INTO tbl_product ( pd_id, cat_id, pd_name, pd_description, pd_qty, price, pd_image ) VALUES ( '$pd_id', '$cat_id', '$pd_name', '$descrip', '$pd_qty', '$price', '$ImageFile' ) ";
$result = mysql_query( $strSQL, $conn )
or die ( "ไม่สามารถเพิ่มข้อมูลลงสู่ตารางได้" . mysql_error() );
echo "$msg";
}
else
$msg = "รูปภาพไม่ใช่ไฟล์ประเภท GIF";
include("bottom.php");
?>
หน้า headder.php
Code (PHP)
<?php
require("auth.inc.php");
if (strtoupper($_SESSION['ses_user']) != 'MASTER') {
header("Location: USERmenu.php?");
exit;
}
include("config.inc.php");
$conn = mysql_connect($dbhost,$dbuser,$dbpass);
if(!$conn)
die("ไม่สามารถเชื่อมต่อฐานข้อมูลได้");
mysql_query("set NAMES tis620 ");
mysql_select_db($dbname,$conn) or die("ไม่สามารถติดต่อฐานข้อมูลได้");
?>
<div align="right"><? echo "<font color='red'>Welcome </font><b><font color='blue'>" . $_SESSION['ses_user'] . " สู่หน้าเว็บผู้ดูแลระบบ </font></b>";
echo " <font color='red'>Login เข้ามาล่าสุดเมื่อ </font><b><font color='blue'>" . $_SESSION['last_log'] . "</font></b>"; ?>
</div>
Tag : PHP, MySQL, HTML/CSS, JavaScript, CakePHP
|
|
|
|
|
|
Date :
2010-09-28 16:13:10 |
By :
jobjab_bcis |
View :
957 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$result = mysql_query( $strSQL) or die (mysql_error());
|
|
|
|
|
Date :
2010-09-28 16:26:09 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่ได้ครับ
|
|
|
|
|
Date :
2010-09-29 09:19:53 |
By :
jobjab_bcis |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
error มีไหมครับ ลอง echo $sql ออกมาดูครับ
|
|
|
|
|
Date :
2010-09-29 09:25:19 |
By :
Dragons_first |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|