Software > Computer programming

Must I fill all for update

(1/1)

guitarzRus:

--- Quote ---I want to update one field in a database table but with this code(which works now if I fill in all
fields). All fields left blank are cleared. I need a solution.
--- End quote ---


--- Code: ---<?php
$link = mysqli_connect("localhost", "root", "", "homedb"); 
// Check connection
if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); }

echo "<center>";echo date(&#39;m/d/y&#39;);echo "<br />";
   //Assign values to variables

$unit=$_POST[&#39;unit&#39;];
$datereceived=$_POST[&#39;datereceived&#39;];
$time=$_POST[&#39;time&#39;];
$area=$_POST[&#39;area&#39;];
$problem=$_POST[&#39;problem&#39;];
$action=$_POST[&#39;action&#39;];
$compday=$_POST[&#39;compday&#39;];
$compmoyr=$_POST[&#39;compmoyr&#39;];
$cost=$_POST[&#39;cost&#39;];
$charge=$_POST[&#39;charge&#39;];
$ordno=$_POST[&#39;ordno&#39;];
$id = &#39;id&#39;;
 $sql = "UPDATE mainttbl SET 
datereceived = &#39;$datereceived&#39;, time = &#39;$time&#39;, area = &#39;$area&#39;, problem = &#39;$problem&#39;, action = &#39;$action&#39;, 
compday = &#39;$compday&#39;, compmoyr = &#39;$compmoyr&#39;, cost = &#39;$cost&#39;, charge = &#39;$charge&#39;, 
ordno =  &#39;$ordno&#39; WHERE id = &#39;$id&#39; ";

 if(mysqli_query($link, $sql)){ echo "record was updated successfully."; } 
else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); }
 // Close connection
mysqli_close($link); 
?>
--- End code ---

Navigation

[0] Message Index

Go to full version