Reputation: 1271
I m Trying to update a data from form but all code is work fine execept it doesnot update on database..
here is my Entities class
class ClothingEntities {
public $PID;
public $PCODE;
public $productname;
public $color;
public $size;
public $stock;
public $price;
public $image;
public $date;
public $review;
public $made;
public $type;
function __construct($PID, $PCODE, $productname, $color, $size, $stock, $price, $image, $date, $review, $made, $type) {
$this->PID = $PID;
$this->PCODE = $PCODE;
$this->productname = $productname;
$this->color = $color;
$this->size = $size;
$this->stock = $stock;
$this->price = $price;
$this->image = $image;
$this->date = $date;
$this->review = $review;
$this->made = $made;
$this->type = $type;
}
Here Is query Class
function UpdateCloth($PCODE,ClothingEntities $cloth){
require 'connection.php';
$link=mysqli_connect($host, $user, $pass, $db);
$link1=mysqli_select_db($link, $db);
$query= sprintf("UPDATE product"
. "SET productname='%s',color='%s',size='%s',stock='%s',price='%s',image='%s',date='%s',review='%s',made='%s',type='%s'"
. "WHERE PCODE='$PCODE'",
mysqli_real_escape_string($link,$cloth->productname),
mysqli_real_escape_string($link,$cloth->color),
mysqli_real_escape_string($link,$cloth->size),
mysqli_real_escape_string($link,$cloth->stock),
mysqli_real_escape_string($link,$cloth->price),
mysqli_real_escape_string($link,"image/".$cloth->image),
mysqli_real_escape_string($link,$cloth->date),
mysqli_real_escape_string($link,$cloth->review),
mysqli_real_escape_string($link,$cloth->made),
mysqli_real_escape_string($link,$cloth->type));
$result= mysqli_query($link, $query);
mysqli_close($link);
return $result;
}
Here is the controller class
function UpdateCloth($PCODE){
$PID=$_POST['txtPID'];
$PCODE=$_POST['txtPCODE'];
$productname=$_POST['txtproductname'];
$color=$_POST['txtcolor'];
$size=$_POST['txtsize'];
$stock=$_POST['txtstock'];
$price=$_POST['txtprice'];
$image=$_POST['txtimage'];
$date=$_POST['txtdate'];
$review=$_POST['txtreview'];
$made=$_POST['txtmade'];
$type=$_POST['txttype'];
$cloth=new ClothingEntities($PID,$PCODE,$productname, $color, $size, $stock, $price, $image, $date, $review, $made, $type);
$clothModel = new ClothingModel();
$clothModel->UpdateCloth($PCODE,$cloth);
}
There is No error on setting the value.. the value can be seen.. and it also display data is updated but in database there will be no change..
[Edited]
function UpdateCloth($PCODE,ClothingEntities $cloth){
require 'connection.php';
$link=mysqli_connect($host, $user, $pass, $db);
$link1=mysqli_select_db($link, $db);
$query= sprintf("UPDATE product "
. " SET productname='%s',color='%s',size='%s',stock='%s',price='%s',image='%s',date='%s',review='%s',made='%s',type='%s'"
. " WHERE PCODE='$PCODE'",
mysqli_real_escape_string($link,$cloth->productname),
mysqli_real_escape_string($link,$cloth->color),
mysqli_real_escape_string($link,$cloth->size),
mysqli_real_escape_string($link,$cloth->stock),
mysqli_real_escape_string($link,$cloth->price),
mysqli_real_escape_string($link,"image/".$cloth->image),
mysqli_real_escape_string($link,$cloth->date),
mysqli_real_escape_string($link,$cloth->review),
mysqli_real_escape_string($link,$cloth->made),
mysqli_real_escape_string($link,$cloth->type));
$result= mysqli_query($link, $query)or die(mysql_error());
mysqli_close($link);
return $result;
}
Upvotes: 0
Views: 47
Reputation: 14982
I believe your error might be in here:
$query= sprintf("UPDATE product"
. "SET productname='%s',color='%s',size='%s',stock='%s',price='%s',image='%s',date='%s',review='%s',made='%s',type='%s'"
. "WHERE PCODE='$PCODE'",
There is no space after product nor before SET, also before WHERE in the line below, which would make this query:
UPDATE productSETproductname='%s',...,type='%s'WHERE PCODE='$PCODE';
Change it to this:
$query= sprintf("UPDATE product "
. " SET productname='%s',color='%s',size='%s',stock='%s',price='%s',image='%s',date='%s',review='%s',made='%s',type='%s'"
. " WHERE PCODE='$PCODE'",
See if it works
Upvotes: 1