Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Must I fill all for update  (Read 36123 times)

0 Members and 1 Guest are viewing this topic.

guitarzRus

    Topic Starter


    Rookie

    • Experience: Experienced
    • OS: Windows 7
    Must I fill all for update
    « on: April 24, 2023, 03:35:41 PM »
    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.

    Code: [Select]
    <?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); 
    ?>