|
|
|
ฟังชั่น Update กดผ่านแล้ว แต่ข้อมูลไม่ยอมเปลี่ยนตามครับ ซึ่งไฟล์อื่นก็เปลี่ยนแล้ว แต่ทำไมไฟล์นี้ไม่ยอมเปลี่ยน |
|
|
|
|
|
|
|
คือผมทำ ทั้งหมด 5 ตาราง
Customer , Employee , Order , Product
ทุกตาราง เวลากด edit แล้วกด update ค่ามันเปลี่ยนแล้วครับ
แต่ Mobile นี้ทำไม กดแล้วมันถึงไม่เปลี่ยนก็ไม่รู้ ตอนกดเปลี่ยน มันเข้า echo "Couldn't update";
UpdateMobile.php
Code (PHP)
<?php
include("connect.php");
include("MobileClass.php");
if(isset($_POST['Update'])){
$objMobile = new Mobile();
$objMobile -> connect();
$objMobile->id_mobile = $_POST['id_mobile'] ;
$objMobile->brand = $_POST['brand'] ;
$objMobile->mobile_Name = $_POST['mobile_Name'] ;
$objMobile->amount = $_POST['amount'] ;
$objMobile->price = $_POST['price'] ;
$objMobile->m_date = $_POST['m_date'] ;
$objMobile->update();
$objMobile->close();
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0;URL=mobile.php\">";
}elseif($_GET['Action']=="Delete"){
$objMobile = new Mobile();
$objMobile->connect();
$objMobile->delete($_GET['id_mobile']);
$objMobile->close();
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0;URL=mobile.php\">";
}elseif($_GET['Action']=="Edit"){
$objMobile = new Mobile();
$objMobile ->connect();
$sql = "SELECT * FROM Mobile WHERE id_mobile= '" .$_GET['id_mobile'] . "'";
$objMobile->query($sql); //จะเก็ยใส่ตัวแปล Results
$row = mysql_fetch_array($objMobile->results,MYSQL_ASSOC); // ส่งตำแหน่งของ Array เป็นตัวอักษร
?>
<html>
<head><title>UpdateMobile</title>
</head>
<center> <h1> <font color="red"> Edit Mobile </h1> </font> </center>
<body bgcolor="black"><center> <font size="5"><b><u>Update Mobile</u></b></font> <br><br>
<TABLE bgcolor="FFCC33">
<form method="POST" name="Mobile" action="UpdateMobile.php">
<tr><td>id_mobile</td>
<td><input type="text" size="15" name="id_mobile" value = <?php echo $row['id_mobile'];?> > </td>
</tr>
<tr><td>brand</td>
<td><input type="text" size="15" name="brand" value = <?php echo $row['brand'];?> > </td>
</tr>
<tr><td>mobile_Name</td>
<td><input type="text" size="15" name="mobile_Name" value = <?php echo $row['mobile_Name'];?> > </td>
</tr>
<tr><td>amount</td>
<td><input type="text" size="15" name="amount" value = <?php echo $row['amount'];?> > </td>
</tr>
<tr><td>price</td>
<td><input type="text" size="15" name="price" value = <?php echo $row['price'];?> > </td>
</tr>
<tr><td>m_date</td>
<td><input type="date" size="15" name="m_date" value = <?php echo $row['m_date'];?> > </td>
<tr><td> <input type="submit" name="Update" value="Edit"> </td>
<td> <input type="reset" value="cancel"> </td>
</tr>
</form>
</TABLE>
</center>
</body>
</html>
<?php } ?>
MobileClass.php
Code (PHP)
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<?php
class Mobile extends db {
var $id_mobile;
var $brand;
var $mobile_Name;
var $amount;
var $price;
var $m_date;
function insert(){
$sql = "INSERT INTO Mobile VALUE ('"
. $this->id_mobile ."','"
. $this->brand ."','"
. $this->mobile_Name ."','"
. $this->amount ."','"
. $this->price ."','"
. $this->m_date ."')";
if($this->results= mysql_query($sql)){
return true;
}else{
echo "Couldn't insert data to Mobile";
return false ;
}
}
function update(){
$sql = "update Mobile SET
id_mobile ='" .$this->id_mobile ."',"
."brand='" .$this->brand ."',"
."mobile_Name='" .$this->mobile_Name ."',"
."amount='" .$this->amount ."',"
."price='" .$this->price ."',"
."m_date='" .$this->m_date ."',"
. "WHERE id_mobile='".$this->id_mobile."'" ;
if($this->results=mysql_query($sql)){
echo "update successful";
return true ;
}else{
echo "Couldn't update";
return false;
}
}
function delete($id_mobile){
$sql="DELETE FROM Mobile WHERE id_mobile='" . $id_mobile . "'";
if($this->results = mysql_query($sql)){
return true ;
}else{
echo "Couldn't Delete" .$id_mobile. "\n" ;
return false ;
}
}
}
?>
Tag : PHP, HTML/CSS
|
ประวัติการแก้ไข 2014-12-16 01:10:56
|
|
|
|
|
Date :
2014-12-15 23:26:33 |
By :
xgabpyz |
View :
687 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|