CodeLobster IDE

Free cross-platform PHP IDE (HTML, PHP, CSS, JavaScript, Python code editor) with support Drupal, Joomla, Twig, JQuery, BackboneJS, LaravelJS, Node.js, CodeIgniter, CakePHP, Laravel, Magento, MeteorJS, Phalcon, Symfony, VueJS, WordPress, Yii
It is currently Tue Mar 19, 2024 8:45 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Must I fill all for update
PostPosted: Mon Apr 24, 2023 9:31 pm 
Offline

Joined: Mon Apr 03, 2023 9:50 pm
Posts: 5
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:
<?php
$link = mysqli_connect("localhost", "root", "", "homedb");
// Check connection
if($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 connection
mysqli_close($link);
?>


Top
 Profile  
 
 Post subject: Re: Must I fill all for update
PostPosted: Tue May 02, 2023 8:53 am 
Offline
Site Admin

Joined: Wed Sep 12, 2007 2:18 pm
Posts: 3931
Hi.

Please, look at the correct sample in the attachment.

Thanks,
Codelobster Team.


Attachments:
NewFile1.txt [1000 Bytes]
Downloaded 651 times
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2016 phpBB Group