Hello every one i am trying to update the product table in my database the user must enter the id of the product to make the update this is the form
<form id="myform"method="post"action="update.php">
<table class="userinf">
<tr>
<td><label class="labelii">PID</label></td>
<td><input id ="edtxt" class ="itxt"type="text" name="PID"required></td>
<td></td>
</tr>
<tr>
<td><label class="labelii">Name</label></td>
<td><input id ="iitxt1" class ="itxt"type="text" name="Name" r></td>
<td><button type="submit" class="Ebutton" onclick="submitform()">Update</button></td>
</tr>
<tr>
<td><label class="labelii">Picture</label></td>
<td><input id ="iitxt2" class ="itxt" type="text" name="Picture" ></td>
<td><button type="submit" class="Ebutton" onclick="submitform()">Update</button></td>
</tr>
<tr>
<td><label class="labelii">Price</label></td>
<td><input id ="iitxt3" class ="itxt" type = "text" name="Price" patte="[-+]?([0-9]*.[0-9]+|[0-9]+)"></td>
<td><button type="submit" class="Ebutton" onclick="submitform()">Update</button></td>
</tr>
<tr>
<td><label class="labelii">Type</label></td>
<td><input id ="iitxt4" class ="itxt" type="text" name="Type"></td>
<td><button type="submit" class="Ebutton" onclick="submitform()">Update</button></td>
</tr>
<tr>
<td><label class="labelii">Stock</label></td>
<td><input id ="iitxt5" class ="itxt"type="number" name="Stock"></td>
<td><button type="submit" class="Ebutton" onclick="submitform()">Update</button></td>
</tr>
<tr>
<td></td>
<td><button type="submit" class="Ebutton" onclick="submitform()">Update All</button></td>
<td></td>
</tr>
</table>
</form>
this is the php code that make the update , the query i toke it from the DB
if(isset($_POST["PID"])){
$PID=$_POST['PID'];
}
if(isset($_POST["Name"]) && isset($_POST["Picture"]) && isset($_POST["Price"]) && isset($_POST["Type"]) && isset($_POST["Stock"])){
$Name=$_POST['Name'];
$Picture=$_POST['Picture'];
$Price=floatval($_POST['Price']);
$Type=$_POST['Type'];
$Stock=intval($_POST['Stock']);
$query="UPDATE `product` SET `Name` = '$Name' , `Picture` = '$Picture', `Price` = '$Price' ,`Type` = '$Type' ,`Stock` = '$Stock',WHERE `product`.`PID` = '".$PID."'";
}
else if (isset($_POST["Name"])){
$Name=$_POST['Name'];
$query="UPDATE `product` SET `Name` = '$Name' WHERE `product`.`PID` = '".$PID."'";
}
else if(isset($_POST["Picture"])){
$Picture=$_POST['Picture'];
$query="UPDATE `product` SET `Picture` = '$Picture' WHERE `product`.`PID` ='".$PID."'";
}
else if( isset($_POST["Price"])){
$Price=floatval($_POST['Price']);
$query="UPDATE `product` SET `Price` = '$Price' WHERE `product`.`PID` = '".$PID."'";
}
else if(isset($_POST["Type"])){
$Type=$_POST['Type'];
$query="UPDATE `product` SET `Type` = '$Type' WHERE `product`.`PID` = '".$PID."'";
}
else if(isset($_POST["Stock"])){
$Stock=intval($_POST['Stock']);
$query="UPDATE `product` SET `Stock` = '$Stock' WHERE `product`.`PID` = '".$PID."'";
}
if i update the price the name get erased if i update the name i get the error
could not execute query
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE product.PID = 'p_99'' at line 1
the query is not at line 1 at all
