Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.
Computer Hope forum e-mail issues and down time
0 Members and 1 Guest are viewing this topic.
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.
<?php$link = mysqli_connect("localhost", "root", "", "homedb"); // Check connectionif($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); }echo "<center>";echo date('m/d/y');echo "<br />"; //Assign values to variables$unit=$_POST['unit'];$datereceived=$_POST['datereceived'];$time=$_POST['time'];$area=$_POST['area'];$problem=$_POST['problem'];$action=$_POST['action'];$compday=$_POST['compday'];$compmoyr=$_POST['compmoyr'];$cost=$_POST['cost'];$charge=$_POST['charge'];$ordno=$_POST['ordno'];$id = 'id'; $sql = "UPDATE mainttbl SET datereceived = '$datereceived', time = '$time', area = '$area', problem = '$problem', action = '$action', compday = '$compday', compmoyr = '$compmoyr', cost = '$cost', charge = '$charge', ordno = '$ordno' WHERE id = '$id' "; if(mysqli_query($link, $sql)){ echo "record was updated successfully."; } else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } // Close connectionmysqli_close($link); ?>