|
|
|
insert product กับ update product ลง database ไม่ได้ค่ะ ช่วยดูให้หน่อยนะคะ |
|
|
|
|
|
|
|
จากหน้าเพจไม่สามารถ insert product กับ update product ลง database
แต่ delete product ได้แล้วค่ะ
หาสาเหตุไม่เจอจริงๆค่ะ ช่วยดูให้หน่อยนะคะ
database product
admin_product.php
<?php
session_start();
$ebits = ini_get('error_reporting');
error_reporting($ebits ^ E_NOTICE);
$user_id=$_SESSION['user_id'];
$username=$_SESSION['username'];
$firstname=$_SESSION['firstname'];
$role=$_SESSION['role'];
include("connect.php");
$ok=$_POST['submit'];
$name=$_POST['name'];
$picture=$_POST['pic'];
$type=$_POST['type'];
$price=$_POST['price'];
$detail=$_POST['detail'];
//-----getssss--------------------------------------------------------
$p = $_GET["Page"];
$edit=$_GET['edit'];
$delete=$_GET['delete'];
//update-----------------------------------------------------------------
$upp=$_POST['up'];
$productnamep=$_POST['name_up'];
$picturep=$_POST['pic_up'];
$typeproductp=$_POST['type_up'];
$pricep=$_POST['price_up'];
$detailp=$_POST['detail_up'];
// $upcake=$_POST['update_cake'];
echo $upproduct;
// if(copy($_FILES["filUpload"]["tmp_name"],"myfile/".$_FILES["filUpload"]["name"]))
$pic = "";
$tmpname = md5(microtime());
$url = "images/";
$pic = $tmpname."_".$_FILES["pic"]["name"];
$picp = $tmpname.$_FILES["pic_up"]["name"];
if(isset($ok)){
copy($_FILES["pic"]["tmp_name"],$url.$pic);
$filename= $url.$pic;
$sql="INSERT INTO product VALUES(null,'$product_name','$pic','$type','$detail',$price)";
mysql_query($sql,$con);
?>
<script LANGUAGE="JavaScript">
alert("Add Product");
</script>
<?php
}
if($delete!=null){
$sql_del="DELETE FROM product WHERE product_id=$delete";
mysql_query($sql_del);
$edit="";
$delete="";
$pages=1;
}
if($edit!=null){
if(isset($upp)){
if($_FILES["pic_up"]["name"]!=null){
$filenamep= $url.$picp;
$sql_up="UPDATE product SET product_name='$productnamep',pic='$picturep',type='$typeproductp',detail='$detailp',price='$pricep' WHERE product_id=$edit";
mysql_query($sql_up);
copy($_FILES["pic_up"]["tmp_name"],$url.$picp);
$edit="";
$delete="";
}
if($_FILES["pic_up"]["name"]==null){
$sql_up="UPDATE product SET product_name='$productnamep',type_c='$typeproductp',detail='$detailp',price=$pricep WHERE product_id=$edit";
mysql_query($sql_up);
$edit="";
$delete="";
}
?>
<script LANGUAGE="JavaScript">
alert("Updated Product");
</script>
<?php
}
}
?>
<html>
<head>
<title>Update Product</title>
<meta charset="utf-8">
<link href="css/style.css" rel="stylesheet" type="text/css">
<style type="text/css">
td{
font-family: 'PTSansNarrowRegular';
color:#8c836b;
}
#page #sidebar td {
font-family: 'PTSansNarrowRegular';
color:#ffffff;
}
td a h3{
font-weight:normal;
}
#page #content .content .header .footer .body .list{
font-size:8px;
}
</style>
<script LANGUAGE="JavaScript">
function check_number(input){
if((event.keyCode<48) || (event.keyCode>57)){
event.returnValue = false;
alert('must be numeric ');
} //alert('input number only ');
}
</script>
</head>
<body>
<div id="page"> <!--this is letf page-->
<div id="sidebar"><img id="logo" src="images/logo.gif" width="171" height="239" alt="">
<?php if(!isset($username)){ ?>
<h2>Log in</h2>
<form method="POST" action="login.php">
<table border=0 align="center">
<tr><td>Username</td><td><input type="text" name="username" id="username"/></td></tr>
<tr><td>Password</td><td><input type="password" name="password" id="pasword"/></td></tr>
<tr><td colspan=2 align="center"><input type="submit" name="Submit" value="Log in" />
<a href="forgetpass.php"><input type="button" value="Forget Password"/></a></td></tr>
</table>
<h2>Register</h2>
<a href="register.php" target="_new"><input type="button" value="Register"/></a>
</form>
<?php }else{?>
<h2>Welcome</h2>
<?php echo $firstname; ?> | <a href="logout.php"><input type="button" value="Log out"></a>
<?php }?>
<br/>
<br/>
<br/>
show order
</div>
<div id="content"> <!--this is center page-->
<!-- start of header -->
<div id="header">
<ul class="navigation">
<li><a href="index.php">Home</a></li>
<li><a href="icecream.php">Icecream</a></li>
<li><a href="topping.php">Topping</a></li>
<?php if(isset($username) AND $role=="user"){ ?><li>
<a class="active" href="profile.php">Profile</a></li><?php } ?>
<?php if(isset($username) AND $role=="admin"){ ?><li>
<a class="active" href="profile.php">Admin</a></li><?php } ?>
<li><a href="contact.php">Contact</a></li>
</ul>
</div>
<!-- end of header -->
<!-- start of class content -->
<div class="content">
<div class="content">
<!-- start inner page content box background -->
<div class="header">
<div class="footer">
<div class="body"><!-- start of body -->
<table width="648" bgcolor="#ffffff">
<tr><td><a href="profile.php"><h3><br/><center>My Profile</center></h3></a></td>
<td><a href="edit.php"><h3><br/><center>Edit Profile</center></h3></a></td>
<td><a href="admin_member.php"><h3><br/><center>My Member</center></h3></a></td>
<td><a href="admin_product.php"><h3><br/><center>Update Product</center></h3></a></td></tr>
</table>
<br/>
<form method="POST" action="" enctype="multipart/form-data">
<table cellpadding="10" border =0>
<tr><td colspan="2"><h1>Add Product</h1></td></tr>
<tr>
<td>Name Propuct</td><td><input type="text" name="name"/></td>
</tr>
<tr>
<td>Detail</td><td><textarea name="detail" rows="5" cols="40" ></textarea></td>
</tr>
<tr>
<td>Price</td><td><input type="text" name="price" onKeyPress="check_number()"/></td>
</tr>
<tr>
<td>Type Product</td>
<td><select name="type">
<option value="icecream">Icecream</option>
<option value="topping">Topping</option>
</select></td>
</tr>
<tr>
<td>Picture</td><td><input type="file" name="pic"/></td>
</tr>
<tr>
<td></td><td><input type="submit" value="Add Product" name="submit" onClick="javascript: return chk();" /></td>
</tr>
</table>
<br/>
<br/>
<?php
$sql_pro="SELECT * FROM product ";
$pro=mysql_query($sql_pro);
$Num_Rows = mysql_num_rows($pro);
$Per_Page = 10; // Per Page
if($pages!=1){
$Page = $_GET["Page"];
}
else{$Page =1;}
if(!$Page)
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$sql_pro.=" order by product_id ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($sql_pro);
?>
<?php
$sql_show="SELECT * FROM product ";
$result=mysql_query($sql_show);
?>
<table>
<tr><td><h1>List Of Product</h1></td></tr>
<tr><td>Total <?php echo $Num_Rows;?> Record : <?php echo $Num_Pages;?> Page :
<?php
if($Prev_Page){
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page){
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}else{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages){
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
}?>
</td></tr>
</table>
<br/>
<table border=1 cellpadding="2" cellspacing="0">
<tr width="100%">
<td>ID</td><td>Name</td><td>Picture</td><td>Type</td><td>Price</td><td >Detail</td><td>Update<br/>/Delete</td>
</tr>
<?php
while($row=mysql_fetch_array($objQuery)){
?>
<div class="list">
<tr>
<td><?php echo $row['product_id']; ?></td>
<td><?php if($edit==$row['product_id']){ ?><!----------------------------------name product------------------>
<textarea name="name_up" rows="4" cols="8" ><?php echo $row['product_name']; ?></textarea>
<?php }else{ echo $row['product_name']; }?></td>
<td width="150"><?php if($edit==$row['product_id']){ ?><!----------------------pic product------------------>
<img src="<?php echo $row['pic']; ?>" height="50" width="50"/><br/>
<input type="file" size="7"name="pic_up"/>
<?php }else{ ?>
<img src="<?php echo $row['pic']; ?>" height="50" width="50"/>
<?php } ?></td>
<td width="100"><?php if($edit==$row['product_id']){ ?><!---------------------type product------------------>
<select name="type_up">
<?php if($row['type']=='icecream'){?>
<option value="icecream">Icecream</option>
<option value="topping">Topping</option>
<?php } else if($row['type']=='topping'){?>
<option value="icecream">Icecream</option>
<option value="topping">Topping</option>
<?php } ?>
</select><?php } else{ echo $row['type']; }?></td>
<td><?php if($edit==$row['product_id']){?><!-----------------------------------price product------------------>
<input type="text" name="price_up" size="3" value="<?php echo $row['price'] ;?>" onKeyPress="check_number()"/><?php }else{echo $row['price']; }?></td>
<td width="225"><?php if($edit==$row['product_id']){?><!--------------------detail product------------------>
<textarea name="detail_up" rows="4" cols="10" ><?php echo $row['detail'];?></textarea>
<?php }else{ echo $row['detail']; } ?></td>
<td><?php if($edit==$row['product_id']){?><input type="submit" name="up" value="save" onClick="javascript: return chkup();"/><?php } else{?>
<a href="?Page=<?php echo $Page;?>&edit=<?php echo $row['product_id'];?>"><img src="images/edit.jpg" width="30" height="30" border=0/></a>
<a href="?Page=<?php echo $Page;?>&delete=<?php echo $row['product_id'];?>">
<img src="images/delete.jpg" width="30" height="30" border=0 onClick="javascript:return confirm('Delete?')"/></a><?php } ?></td>
</tr>
</div>
<?php } ?>
</table>
</form>
<table><tr><td>
Total <?php echo $Num_Rows;?> Record : <?php echo $Num_Pages;?> Page :
<?php
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}else{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
}?><br/><br/>
</td></tr></table>
</div>
<!-- end of body -->
</div>
</div>
<!-- end inner page content box background -->
</div>
<!-- start of featured-->
<div class="featured">
</div>
<!-- end of featured-->
<!-- start of section-->
<div class="section">
<div class="about">
</div>
<div class="connect">
</div>
</div>
<!-- end of section-->
</div>
<!-- end of class content -->
<div id="footer">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="icecream.php">Icecream</a></li>
<li><a href="topping.php">Topping</a></li>
<li><a href="profile.php">Profile</a></li>
<li><a href="admin.php">Admin</a></li>
<li><a href="contact.php">Contact</a></li>
</ul>
<span>©2011 <a href="index.html">Frost Sweets Gourmet Ice Cream</a> All Rights Reserved</span>
<ul class="connect">
<li>
FOLLOW US:
</li>
<li>
<a class="facebook" href="http://www.freewebsitetemplates.com/go/facebook"> </a>
</li>
<li>
<a class="twitter" href="http://www.freewebsitetemplates.com/go/twitter/"> </a>
</li>
<li>
<a class="email" href="http://www.freewebsitetemplates.com/misc/contact"> </a>
</li>
<li>
<a class="googleplus" href="http://www.freewebsitetemplates.com/go/googleplus/"> </a>
</li>
</ul>
</div>
</div>
<!-- end of ID content-->
</div>
</body>
</html>
Tag : PHP, MySQL, HTML/CSS
|
|
|
|
|
|
Date :
2013-03-03 10:55:30 |
By :
momaeme |
View :
1186 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
echo $sql="INSERT INTO product VALUES(null,'$product_name','$pic','$type','$detail',$price)";
ออกมาดูก่อนครับ
|
|
|
|
|
Date :
2013-03-03 13:04:14 |
By :
mangkunzo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มีค่าตรงดาต้าเบสที่ต้องการค่ะ
แต่ก็ยังไม่ขึ้นในดาต้าเบสค่ะ
|
|
|
|
|
Date :
2013-03-03 13:54:57 |
By :
momaeme |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|