updating data from php to mysql creating blank data - php

I have a webpage in php which has some form data in sql the user can update the data.
The form is like below:
<?php
$id=$_GET['id'];
$SelSql = "SELECT * FROM `registers` WHERE id=$id";
$res = mysqli_query($link, $SelSql);
$r = mysqli_fetch_assoc($res);
?>
<?php if(isset($fmsg)){ ?><div class="alert alert-danger" role="alert"> <?php echo $fmsg; ?> </div><?php } ?>
<div class="breadcrumbs">
<div class="breadcrumbs-inner">
<div class="row m-0">
<div class="col-sm-4">
<div class="page-header float-left">
<div class="page-title">
<h1>Member Details</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="content">
<div class="animated fadeIn">
<div class="row">
<div class="col-xs-6 col-sm-6">
<div class="card">
<div class="card-body card-block">
<div class="form-group">
<label class=" form-control-label">Member ID</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-id-card-o"></i></div>
<input class="form-control" value="<?php echo $r['id']; ?>" readonly>
</div>
</div>
<form method="post">
<div class="form-group">
<label class=" form-control-label">First Name</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-address-card-o"></i></div>
<input name="fname" class="form-control" value="<?php echo $r['firstname']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Last Name</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-address-card-o"></i></div>
<input name="lname" class="form-control" value="<?php echo $r['lastname']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Mobile Number</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-mobile"></i></div>
<input name="mobile" class="form-control" value="<?php echo $r['mobilenumber']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Company</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-building"></i></div>
<input name="company" class="form-control" value="<?php echo $r['company']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Designation</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-clipboard"></i></div>
<input name="designation" class="form-control" value="<?php echo $r['designation']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Experience</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-sort-numeric-asc"></i></div>
<input name="experience" class="form-control" value="<?php echo $r['experience']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Address</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-map-marker"></i></div>
<input name="address" class="form-control" value="<?php echo $r['address']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Address Line 2</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-map-marker"></i></div>
<input name="addressline2" class="form-control" value="<?php echo $r['addressline2']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">City</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-building-o"></i></div>
<input name="city" class="form-control" value="<?php echo $r['city']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">State</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-map"></i></div>
<input name="state" class="form-control" value="<?php echo $r['state']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Pin</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-map-pin"></i></div>
<input name="pin" class="form-control" value="<?php echo $r['pin']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Country</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-globe"></i></div>
<input name="country" class="form-control" value="<?php echo $r['country']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Whatsapp Number</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-phone-square"></i></div>
<input name="whatsapp" class="form-control" value="<?php echo $r['Whatsapp']; ?>">
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-6">
<div class="card">
<div class="card-body card-block">
<div class="form-group">
<label class=" form-control-label">Alternate Number</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-phone"></i></div>
<input name="alternate" class="form-control" value="<?php echo $r['alternatenumber']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Email</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-envelope"></i></div>
<input name="email" class="form-control" value="<?php echo $r['Email']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Company Registration Number</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-registered"></i></div>
<input name="crn" class="form-control" value="<?php echo $r['CompanyRegNumber']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Date of Incorporation</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-calendar"></i></div>
<input name="doi" class="form-control" value="<?php echo $r['Date_Incorporation_orBusi_Stp']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">GST IN</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-sort-numeric-asc"></i></div>
<input name="gstin" class="form-control" value="<?php echo $r['GSTIN']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Services Offered</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-question-circle"></i></div>
<input name="services" class="form-control" value="<?php echo $r['Services_Offered']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Annual Turnover</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-money"></i></div>
<input name="annualt" class="form-control" value="<?php echo $r['Annual_Turnover']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Fee</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-money"></i></div>
<input name="fee" class="form-control" value="<?php echo $r['Fee']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Mode of Payment</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-credit-card"></i></div>
<input name="mop" class="form-control" value="<?php echo $r['Mode_of_Payment']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Recommended By (A)</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-user"></i></div>
<input name="reca" class="form-control" value="<?php echo $r['Recommended_by_A']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Recommended By (B)</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-user"></i></div>
<input name="recb" class="form-control" value="<?php echo $r['Recommended_by_B']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Terms and Conditions</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-check"></i></div>
<input name="tac" class="form-control" value="<?php echo $r['termsandconditions']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Declaration</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-check"></i></div>
<input name="dec" class="form-control" value="<?php echo $r['Declaration']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Confirmation</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-check"></i></div>
<input name="cof" class="form-control" value="<?php echo $r['confirmation']; ?>">
</div>
</div>
<input type="submit" class="btn btn-primary" value="Update">
</form>
</div>
</div>
</div>
<?php
if(isset($_POST) & !empty($_POST)){
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['mobile'];
$company = $_POST['company'];
$designation = $_POST['designation'];
$experience = $_POST['experience'];
$address = $_POST['address'];
$addressline2 = $_POST['addressline2'];
$city = $_POST['city'];
$state = $_POST['state'];
$pin = $_POST['pin'];
$country = $_POST['country'];
$whatsapp = $_POST['whatsapp'];
$alternate = $_POST['alternate'];
$email = $_POST['email'];
$crn = $_POST['crn'];
$doi = $_POST['doi'];
$gstin = $_POST['gstin'];
$services = $_POST['services'];
$annualt = $_POST['annualt'];
$fee = $_POST['fee'];
$mop = $_POST['mop'];
$reca = $_POST['reca'];
$recb = $_POST['recb'];
$tac = $_POST['tac'];
$dec = $_POST['dec'];
$cof = $_POST['cof'];
}
$UpdateSql = "UPDATE `registers` SET firstname='$fname', lastname='$lname', mobilenumber='$email', experience='$experience',
designation='$designation', company='$company', address='$address', addressline2='$addressline2',
city='$city', state='$state', pin='$pin', country='$country',
Whatsapp='$whatsapp', alternatenumber='$alternate', Email='$email', CompanyRegNumber='$crn',
Date_Incorporation_orBusi_Stp='$doi', GSTIN='$gstin', Services_Offered='$services', Annual_Turnover='$annualt',
Declaration='$dec', Fee='$fee', confirmation='$cof', Mode_of_Payment='$mop',
Recommended_by_A='$reca', Recommended_by_B='$recb', termsandconditions='$tac' WHERE id=$id";
$res = mysqli_query($link, $UpdateSql);
if($res){
header('location: update.php');
}else{
$fmsg = "Failed to update data.";
}
?>
the update feature is working completely fine, when the user loads this page, the data is displayed in the form which is editable by user,now the problem is when the user updates the data, the page reloads and updates the data in database but, the page is displayed with empty values in the input fields, such that if the user clicks the update button again by mistake, the database field becomes blank. what is the problem in my code, what should i do to stop this mistake?

The issue is fundamentally how you are passing parameters. If you are POSTing then the parameter id will not be accessible with your current code, which expects id to be a GET parameter. Try this:
$id=$_POST['id'];
Or better yet,
$id=$_REQUEST['id'];
The $_REQUEST variable is an associative array that by default contains the contents of $_GET, $_POST and $_COOKIE. Since it seems that you need the id parameter for both GET and POST methods, $_REQUEST should be used here.
UPDATE
Your mysqli_query($link, $UpdateSql) function should be wrapped in the if(isset($_POST) & !empty($_POST)) condition. It looks like it is executing on each load the way the code currently is.
if(isset($_POST) & !empty($_POST)){
...
$UpdateSql = "....."
$res = mysqli_query($link, $UpdateSql);
}

Pass id, when you are redirecting page, on success as following
if($res){
header('location: update.php?id='.$id);
exit;
}else{
$fmsg = "Failed to update data.";
}

Related

Warning: Missing argument 3 for DB::update(), called in

I'm getting the following error message:
Warning: Missing argument 3 for DB::update(), called in C:\xampp\htdocs\my.sleeptrak.com\users\step-1-edit.php on line 51 and defined in C:\xampp\htdocs\my.sleeptrak.com\users\classes\DB.php on line 261
Here is my db.php:
public function update($table, $id, $fields){
$sql = "UPDATE {$table} SET " . (empty($fields) ? "" : "`") . implode("` = ? , `", array_keys($fields)) . (empty($fields) ? "" : "` = ? ");
$is_ok = true;
if (!is_array($id)) {
$sql .= "WHERE id = ?";
$fields[] = $id;
} else {
if (empty($id))
return false;
if ($where_text = $this->_calcWhere($id, $fields, "and", $is_ok))
$sql .= "WHERE $where_text";
}
if ($is_ok)
if (!$this->query($sql, $fields)->error())
return true;
return false;
}
And here is my edit.php
<form class="needs-validation" method="post">
<div class="offset-2 col-md-8 order-md-1">
<div class="card">
<div class="card-body">
<?php
if(isset($_POST['save'])) {
$fields = array(
"PatientFirstName" => $_POST['PatientFirstName'],
"PatientLastName" => $_POST['PatientLastName'],
"PatientStreet" => $_POST['PatientStreet'],
"PatientCity" => $_POST['PatientCity'],
"PatientProvince" => $_POST['PatientProvince'],
"PatientPostalCode" => $_POST['PatientPostalCode'],
"PatientCountry" => $_POST['PatientCountry'],
"PatientEmail" => $_POST['PatientEmail'],
"PatientPhone" => $_POST['PatientPhone'],
"PatientDOB" => $_POST['PatientDOB'],
"PatientBMI" => $_POST['PatientBMI'],
"PhysicianName" => $_POST['PhysicianName'],
"PhysicianEmail" => $_POST['PhysicianEmail']
);
$db->update("patients", $fields);
//print_r($db->errorInfo());
echo '<div class="alert alert-success mb-4" role="alert">The patient has been successfully updated!</div>';
} else {
?>
<h4 class="mb-3">Edit Patient <?php echo $PatientFirstName . ' ' . $PatientLastName; ?></h4>
<div class="row">
<div class="col-md-6 mb-3">
<label for="PatientFirstName">Patient first name</label>
<input type="text" class="form-control" name="PatientFirstName" value="<?php echo $PatientFirstName; ?>">
<div class="invalid-feedback">Valid first name is required.</div>
</div>
<div class="col-md-6 mb-3">
<label for="PatientLastName">Patient last name</label>
<input type="text" class="form-control" name="PatientLastName" value="<?php echo $PatientLastName; ?>">
<div class="invalid-feedback">Valid last name is required.</div>
</div>
</div>
<div class="row">
<div class="col-md-4 mb-3">
<label for="PatientDOB">Patient DOB</label>
<input type="date" class="form-control" name="PatientDOB" value="<?php echo $PatientDOB; ?>">
</div>
<div class="col-md-4 mb-3">
<label for="email">Email</label>
<input type="text" class="form-control" name="PatientEmail" value="<?php echo $PatientFirstName; ?>">
</div>
<div class="col-md-4 mb-3">
<label for="PatientPhone">Phone</label>
<input type="text" class="form-control" name="PatientPhone" value="<?php echo $PatientPhone; ?>">
<div class="invalid-feedback">Valid last name is required.</div>
</div>
</div>
</div><!--card-body-->
</div><!--card-->
<div class="card mt-3">
<div class="card-body">
<h4>Patient Address</h4>
<div class="row">
<div class="col-md-8 mb-3">
<label for="PatientStreet">Street</label>
<input type="text" class="form-control" name="PatientStreet" value="<?php echo $PatientStreet; ?>">
<div class="invalid-feedback">Valid address is required.</div>
</div>
<div class="col-md-4 mb-3">
<label for="PatientCity">City</label>
<input type="text" class="form-control" name="PatientCity" value="<?php echo $PatientCity; ?>">
<div class="invalid-feedback">
City is required.
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 mb-3">
<label for="state">Province / State</label>
<input type="text" class="form-control" name="PatientProvince" value="<?php echo $PatientProvince; ?>">
<div class="invalid-feedback">
Please provide a valid province/state.
</div>
</div>
<div class="col-md-3 mb-3">
<label for="PatientPostalCode">Postal Code / Zip</label>
<input type="text" class="form-control" name="PatientPostalCode" value="<?php echo $PatientPostalCode; ?>">
<div class="invalid-feedback">
Postal Code / Zip Code is required.
</div>
</div>
<div class="col-md-5 mb-3">
<label for="PatientCountry">Country</label>
<input type="text" class="form-control" name="PatientCountry" value="<?php echo $PatientCountry; ?>">
<div class="invalid-feedback">
Please select a valid country.
</div>
</div>
</div>
</div><!--card-body-->
</div><!--card-->
<div class="card mt-3">
<div class="card-body">
<h4>Body Mass Index</h4>
<div class="row">
<div class="col-md-6 mb-3">
<label for="PatientBMI">Patient BMI</label>
<input type="text" class="form-control" name="PatientBMI" value="<?php echo $PatientBMI; ?>">
</div>
</div>
</div><!--card-body-->
</div><!--card-->
<div class="card mt-3">
<div class="card-body">
<div class="row">
<div class="col-md-6 mb-3">
<label for="PhysicianName">Physician Name</label>
<input type="text" class="form-control" name="PhysicianName" value="<?php echo $PhysicianName; ?>">
<div class="invalid-feedback">Valid last name is required.</div>
</div>
<div class="col-md-6 mb-3">
<label for="PhysicianEmail">Physician Email</label>
<input type="text" class="form-control" name="PhysicianEmail" value="<?php echo $PhysicianEmail; ?>">
</div>
</div>
</div><!--card-body-->
</div><!--card-->
<button class="btn btn-primary btn-lg btn-block mt-4" name="save" type="submit">Update</button>
</div>
</form>
I research all same errors on this form but i can't fix it. I tried to replace this: php public function update($table, $id, $field) with this public function update($table, $id, $fields=null) but is not working for me. How ever, the error is gone when i put null in function but still don't save in db my changes.
you have to write all arguments for update method
$db->update("patients", $id, $fields);
you missed $id.

Adding an additional field breaks my query

When I add an additional field to my query, it fails. I have checked the spelling 20 or more times....I do not know what is wrong.. Please help!!
Working code BELOW
if(isset($_POST['UPDATE_RAW'])) {
extract($_POST);
$sql=mysqli_query($db,"update nma_raw set NMA_System='$nmasystem',NMA_Ticket_Number='$nmaticketnum',Tkt_Priority='$tktpriority',Created_On_Worklist='$createdonworklist',Create_Date='$createdate',Create_Time='$createtime',Days_Old='$daysold',Interval_Onlist='$intervalonlist',Check_Status='$checkstatus',Ticket_Status='$ticketstatus',Relate_Status='$relatestatus',WFA_TR_Num='$wfatrnum',Recent_WFA_Dispatch_Status='$recentwfadispatchstatus',Last_Owner='$lastowner',Entity_Status='$entitystatus',Entity='$entity',First_Cond_Type='$firstcondtype',Last_Cond_Type='$lastcondtype',State='$st',CLLI='$clli',Check_Active='$checkactive',Check_Jepd='$checkjepd' WHERE ID='$id'");
if($sql) {
echo "<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else {
echo "<script>alert('Some ERRORS');</script>";
}
}
NOT WORKING CODE BELOW!
if(isset($_POST['UPDATE_RAW'])) {
extract($_POST);
$sql = mysqli_query($db,"update nma_raw set NMA_System='$nmasystem',NMA_Ticket_Number='$nmaticketnum',Tkt_Priority='$tktpriority',Created_On_Worklist='$createdonworklist',Create_Date='$createdate',Create_Time='$createtime',Days_Old='$daysold',Interval_Onlist='$intervalonlist',Check_Status='$checkstatus',Ticket_Status='$ticketstatus',Relate_Status='$relatestatus',WFA_TR_Num='$wfatrnum',Recent_WFA_Dispatch_Status='$recentwfadispatchstatus',Last_Owner='$lastowner',Entity_Status='$entitystatus',Entity='$entity',First_Cond_Type='$firstcondtype',Last_Cond_Type='$lastcondtype',State='$st',CLLI='$clli',Check_Active='$checkactive',Check_Jepd='$checkjepd', Resolved_Date='$resolved_date' WHERE ID='$id'");
if($sql) {
echo "<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else {
echo "<script>alert('Some ERRORS');</script>";
}
}
HERE IS A PICTURE OF MY DB SCHEMA
enter image description here
HERE IS THE TOTAL PHP FILE
<?php include_once "header.php";?>
<section class="content">
<div class="page-body clearfix">
<?php
$id=$_REQUEST['id'];
$sql=mysqli_query($db,"SELECT NMA_RAW.*, NMA_RAW.Check_Status, NMA_RAW.Resolved_Date, NMA_RAW.Filtered_Date FROM NMA_RAW WHERE (((NMA_RAW.Check_Status)='OK') AND ((NMA_RAW.Resolved_Date) Is Null) AND ((NMA_RAW.Filtered_Date) Is Null)) AND NMA_RAW.ID = $id;");
$row = mysqli_fetch_array($sql);
?>
<div class="panel panel-default">
<div class="panel-heading">NMA Active Ticket Form</div>
<div class="panel-body">
<form class="form-horizontal" action="" method="post">
<div class="form-group">
<div class="col-sm-4">
<label>NMA System</label>
<input type="text" id="nma_system" class="form-control" placeholder="NMA System" value="<?= $row['NMA_System']; ?>" name="nmasystem">
</div>
<div class="col-sm-4">
<label>NMA Ticket Number</label>
<input type="text" id="nma_ticket_number" class="form-control" placeholder="NMA Ticket Number" value="<?= $row['NMA_Ticket_Number']; ?>" name="nmaticketnum">
</div>
<div class="col-sm-4">
<label>Ticket Priority</label>
<input type="text" id="ticket_priority" class="form-control" placeholder="Ticket Priority" value="<?= $row['Tkt_Priority']; ?>" name="tktpriority">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Created On Worklist</label>
<input type="text" id="created_on_work_list" class="form-control" placeholder="Created On Worklist" value="<?= $row['Created_On_Worklist']; ?>" name="createdonworklist">
</div>
<div class="col-sm-4">
<label>Created Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="created_date" class="form-control" placeholder="Created Date" value="<?= $row['Create_Date']; ?>" name="createdate">
</div>
</div>
<div class="col-sm-4">
<label>Created time</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="time" id="created_time" class="form-control" placeholder="Created Time" value="<?= $row['Create_Time']; ?>" name="createtime">
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Days Old</label>
<input type="text" id="days_old" class="form-control" placeholder="Days old" value="<?= $row['Days_Old']; ?>" name="daysold">
</div>
<div class="col-sm-4">
<label>Check</label>
<input type="text" id="check" class="form-control" placeholder="Check" value="<?= $row['Check_Status']; ?>" name="checkstatus">
</div>
<div class="col-sm-4">
<label>Ticket Status</label>
<input type="text" id="ticket_status" class="form-control" placeholder="Ticket Status" value="<?= $row['Ticket_Status']; ?>" name="ticketstatus">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Interval</label>
<input type="text" id="interval" class="form-control" placeholder="Interval" value="<?= $row['Interval_Onlist']; ?>" name="intervalonlist">
</div>
<div class="col-sm-4">
<label>Related Status</label>
<input type="text" id="relate_status" class="form-control" placeholder="Relate Status" value="<?= $row['Relate_Status']; ?>" name="relatestatus">
</div>
<div class="col-sm-4">
<label>WFA TR Num</label>
<input type="text" id="wfa_tr_num" class="form-control" placeholder="WF TR Num" value="<?= $row['WFA_TR_Num']; ?>" name="wfatrnum">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Recent WFA Dispatch Status</label>
<input type="text" id="recent_wfa_dispatch_status" class="form-control" placeholder="Recent WFA Dispatch Status"
value="<?= $row['Recent_WFA_Dispatch_Status']; ?>" name="recentwfadispatchstatus">
</div>
<div class="col-sm-4">
<label>Entity Status</label>
<input type="text" id="entity_status" class="form-control" placeholder="Intity Status" value="<?= $row['Entity_Status']; ?>" name="entitystatus">
</div>
<div class="col-sm-4">
<label>Entity</label>
<input type="text" name="entity" id="entity" class="form-control" placeholder="Entity" value="<?= $row['Entity']; ?>" name="entity">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Last Owner</label>
<input type="text" id="last_owner" class="form-control" placeholder="Last Owner" value="<?= $row['Last_Owner']; ?>" name="lastowner">
</div>
<div class="col-sm-4">
<label>First Cond Type</label>
<input type="text" id="first_cond_type" class="form-control" placeholder="First Cond Type" value="<?= $row['First_Cond_Type']; ?>" name="firstcondtype">
</div>
<div class="col-sm-4">
<label>Last Cond Type</label>
<input type="text" id="last_cond_type" class="form-control" placeholder="Last Cond Type" value="<?= $row['Last_Cond_Type']; ?>" name="lastcondtype">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>State</label>
<input type="text" id="state" class="form-control" placeholder="State" value="<?= $row['State']; ?>" name="st">
</div>
<div class="col-sm-4">
<label>Check Active</label>
<input type="text" id="check_active" class="form-control" placeholder="Check Active" value="<?= $row['Check_Active']; ?>" name="checkactive">
</div>
<div class="col-sm-4">
<label>Check Jepd</label>
<input type="text" name="check_jepd" id="check_jepd" class="form-control"placeholder="Check Jepd" value="<?= $row['Check_Jepd']; ?>" name="checkjepd">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>CLLI</label>
<input type="text" id="clli" class="form-control" placeholder="CLLI" value="<?= $row['CLLI']; ?>" name="clli">
</div>
<div class="col-sm-4">
<label>Resolved Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="resolved_date" class="form-control" placeholder="Resolved_Date" value="<?= $row['Resolved_Date']; ?>" name="resolved_date">
</div>
</div>
<div class="col-sm-4">
<label>Filtered Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="filtered_date" class="form-control" placeholder="Filtered Date" value="<?= $row['Filtered_Date']; ?>" name="filtereddate">
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Filtered By</label>
<input type="text" id="filtered_by" class="form-control" placeholder="Filtered by" value="<?= $row['Filtered_By']; ?>" name="filteredby">
</div>
<div class="col-sm-4">
<label>Restored Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="restored_date" class="form-control" placeholder="Restored_Date" value="<?= $row['Restored_Date']; ?>" name="restoreddate">
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-4 ">
<label class="text-bold"> NMA Comments subform </label>
</div>
<div class="col-sm-4">
</div>
</div>
<hr>
<div class="form-group">
<?php
$io = mysqli_query($db,"select * from NMA_Comments where NMA_Tkt_Num='$row[NMA_Ticket_Number]'");
$tr=mysqli_fetch_assoc($io);
?>
<div class="col-sm-4">
<label>NMA Ticket Number</label>
<input type="text" name="NMA_Ticket_Number" id="nma_ticket_number" class="form-control" placeholder="NMA Ticket Number" value="<?php echo $tr['NMA_Tkt_Num']; ?>" >
</div>
<div class="col-sm-4">
<label>NMA Notes</label>
<textarea type="text" name="NMA_Notes" id="nma_notes" class="form-control" placeholder="NMA Notes"><?php echo $tr['NMA_Notes']; ?></textarea>
</div>
<div class="col-sm-4">
<label>NMA Note Date</label>
<input type="text" name="NMA_Ticket_Date" id="nma_ticket_number" class="form-control" placeholder="NMA Ticket Number" value="<?php echo $tr['NMA_Note_Date']; ?>">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<button class="btn btn-primary" name="UPDATE_RAW"> Save and Close</button>
</div>
<div class="col-sm-4">
<button class="btn btn-success" name="MOVE_TO_RESOLVED"> Resolved and Close</button>
</div>
<div class="col-sm-4">
<button class="btn btn-danger" name="MOVE_TO_INHIBITS"> Inhibit and Close</button>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
<?php
if(isset($_POST['UPDATE_RAW'])){
extract($_POST);
//print_r($_POST);
$sql=mysqli_query($db,"update nma_raw set NMA_System='$nmasystem',NMA_Ticket_Number='$nmaticketnum',Tkt_Priority='$tktpriority',Created_On_Worklist='$createdonworklist',Create_Date='$createdate',Create_Time='$createtime',Days_Old='$daysold',Interval_Onlist='$intervalonlist',Check_Status='$checkstatus',Ticket_Status='$ticketstatus',Relate_Status='$relatestatus',WFA_TR_Num='$wfatrnum',Recent_WFA_Dispatch_Status='$recentwfadispatchstatus',Last_Owner='$lastowner',Entity_Status='$entitystatus',Entity='$entity',First_Cond_Type='$firstcondtype',Last_Cond_Type='$lastcondtype',State='$st',CLLI='$clli',Check_Active='$checkactive',Check_Jepd='$checkjepd', Resolved_Date='$resolved_date' WHERE ID='$id'");
if($sql){
echo"<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else{
echo"<script>alert('Some ERRORS');</script>";
}
}
?>
<?php
if(isset($_POST['MOVE_TO_INHIBITS'])){
extract($_POST);
//$print_r($_POSt);
$sql=mysqli_query($db,"INSERT INTO nma_main_table SELECT * FROM nma_raw where ID='$id'");
if($sql){
echo"<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else{
echo"<script>alert('Some ERRORS');</script>";
}
// sql to delete a record
$sql=mysqli_query($db,"DELETE FROM nma_raw WHERE ID='$id'");
if ($sql){
echo "Record Inhibited successfully";
} else {
echo "<script>alert('Error in deletion');</script>";
}
}
?>
<?php
if(isset($_POST['MOVE_TO_RESOLVED'])){
extract($_POST);
//$print_r($_POSt);
$sql=mysqli_query($db,"INSERT INTO nma_main_table SELECT * FROM nma_raw where ID='$id'");
if($sql){
echo"<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else{
echo"<script>alert('Some ERRORS');</script>";
}
// sql to delete a record
$sql=mysqli_query($db,"DELETE FROM nma_raw WHERE ID='$id'");
if ($sql){
echo "Record Resolved successfully";
} else {
echo "<script>alert('Error in deletion');</script>";
}
}
?>
<?php include_once "footer.php";?>
If the error you're getting is Incorrect date value: '' for column 15daytkt.nma_raw.Resolved_Date (as you've mentioned in the comments) :
It looks like you are passing an empty string to the Resolved_Date column, and it's invalid. Please make sure you're actually passing a valid date string in this format 2019-11-15. Usually, the HTML form inputs with the date type return this format.
You can verify this case by setting the value to NULL if it's empty. Try changing the query as below:
$sql = mysqli_query($db,"update nma_raw set NMA_System='$nmasystem', Resolved_Date=NULLIF($resolved_date, '') WHERE ID='$id'");
Note the NULLIF($resolved_date, '') part. It will basically set the value to null if it is empty.
Hope it helps.

php - submit button is not working in isset

I am trying to add a form in my html which will get 12 input box and save it to mysql. but its echoing failed as because of submit button perhaps. because in if for the isset submit button the else is forwarding message. Code for my html
<body class="templatemo-bg-image-2">
<div class="container">
<div class="col-md-12">
<form class="form-horizontal templatemo-contact-form-1" role="form" action="input.php" method="post">
<div class="form-group">
<div class="col-md-12">
<h1 class="margin-bottom-15">Marketing Samurai 2017</h1>
<h2 class="margin-bottom-15">Registration form</h2>
<p>This contact form is provided by templatemo that can be used for your websites. Credit goes to <a rel="nofollow" href="http://unsplash.com">Unsplash</a> for the background image.</p>
</div>
<hr>
<h4 class="margin-bottom-15">Team Info</h4>
<hr>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">University Name</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-university"></i>
<input name="uname" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Team</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-users"></i>
<input name="tname" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Trix Id</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-money"></i>
<input name="tcode" type="text" class="form-control" id="name" placeholder="Bkash transection Code">
</div>
</div>
</div>
<h4 class="margin-bottom-15">Leader Info</h4>
<hr>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Name</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-user"></i>
<input name="lname" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Email</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-envelope-o"></i>
<input name="lmail" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Contact</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-phone"></i>
<input name="lcont" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<h4 class="margin-bottom-15">1st Member Info</h4>
<hr>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Name</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-user"></i>
<input name="m1name" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Email</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-envelope-o"></i>
<input name="m1mail" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Contact</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-phone"></i>
<input name="m1cont" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<h4 class="margin-bottom-15">2nd Member Info</h4>
<hr>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Name</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-user"></i>
<input name="m2name" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Email</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-envelope-o"></i>
<input name="m2mail" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Contact</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-phone"></i>
<input name="m2cont" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<button type="submit" value="Submit" name="submit" class="btn btn-success pull-right">></button>
</div>
</div>
</form>
</div>
</div>
Code for php
<?php
$con = mysqli_connect('localhost','root','');
if(!$con){
echo 'Not Connected To Server';
}
if (!mysqli_select_db ($con,'test')) {
echo 'Database Not Selected';
}
if (isset($_POST['submit'])){
$uni = $_POST['uname'];
$team = $_POST['tname'];
$trix = $_POST['tcode'];
$leader = $_POST['lname'];
$lemail = $_POST['lmail'];
$leadercon = $_POST['lcont'];
$mname = $_POST['m1name'];
$memail = $_POST['m1mail'];
$mcon = $_POST['m1cont'];
$mname3 = $_POST['m2name'];
$memail3 = $_POST['m2mail'];
$mcon3 = $_POST['m2cont'];
$sql = "INSERT INTO 'memberdetails' (uninam, team, trixid, mem, mail, cont, mem1, mail1, con1, mem2, mail2, con2) VALUES ('$uni', '$team', '$trix', '$leader', '$lemail', '$leadercon', '$mname', '$memail', '$mcon', '$mname3', '$memail3', '$mcon3' )";
if (!mysqli_query($con,$sql))
{
echo 'Not Inserted';
}
else
{
echo 'Inserted Successfully';
}
header("refresh:2; url=index.html");
} else {
echo "failed";
}
I haven't made any validation yet. and I am trying with msqli and database, table is connecting then why the error is coming? I just made the submit button just to insert docs. whats should I do to prevent the fail message. Thanks in advance. :)
Submit must be <input> with name or it won't be available using $_POST['submit']
<input type="submit" value="Submit" name="submit" />
Try to remove "submit" text from name of form button and replace with another text
<button type="submit" value="Submit" name="form_sumit" class="btn btn-success pull-right">></button>

Blank Page or Empty Page when seeing update.php

UPDATE.php
<?php
include('DB.php');
if(isset($_GET['id'])){
$id=$_GET['id'];
if(isset($_POST['update'])){
$name=mysqli_real_escape_string($link,$_POST["ename"]);
$email=mysqli_real_escape_string($link,$_POST["eemail"]);
$enpassword=mysqli_real_escape_string($link,$_POST["epassword"]);
$dateofbirth=mysqli_real_escape_string($link,$_POST["edateofbirth"]);
$mobile=mysqli_real_escape_string($link,$_POST["emobile"]);
$presentaddress=mysqli_real_escape_string($link,$_POST["epresentaddress"] );
$drivinglicense=mysqli_real_escape_string($link,$_POST["edrivinglicense"]);
if(mysqli_query("UPDATE hrmsinfo SET emp_name=$name,emp_email=$email,emp_password=$enpassword,emp‌​_dob=$dateofbirth,em‌​p_phno=$mobile,emp_a‌​ddress=$presentaddress,emp_proof=$drivin‌​glicense WHERE emp_id='$id'")){
$msg="Successfully Updated!!";
header('Location:VIEW.php');
}
else{
$msg="Unsucessfull!!";
}
}
} //update ends here
?>
When ever i try to execute this update code with following edit code it displays blank page help me with it
The below is edit code which executes perfectly but update doesnt work at all help me where am i stuck
<?php
//error_reporting(0);
include("DB.php");
if(isset($_GET['id'])){
$id=$_GET['id'];
$sql="SELECT * FROM hrmsinfo WHERE emp_id='$id'";
$sqll=mysqli_query($link,$sql);
while($profile=mysqli_fetch_array($sqll)){
$username=$profile['emp_name'];
$usermail=$profile['emp_email'];
$userdob=$profile['emp_dob'];
$usermobile=$profile['emp_phno'];
$useraddress=$profile['emp_address'];
$userproof=$profile['emp_proof'];
?>
<div>
<form action="UPDATE.php" method="post" name="insertform">
<div class="form-group">
<div class="row">
<div class="col-xs-3">Name:</div>
<div class="col-xs-4"><input type="text" class="form-control" name="ename" placeholder="Enter Name" value="<?php echo $username; ?>" id="inputid"></div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-3">Email:</div>
<div class="col-xs-4"><input type="text" class="form-control" name="eemail" placeholder="Enter Email" value="<?php echo $usermail; ?>" id="inputid"></div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-3">Password:</div>
<div class="col-xs-3"><input type="password" class="form-control" name="epassword" id="inputid" placeholder="Enter Password" id='input_id'></div>
<div class="col-xs-3"><input type="password" class="form-control" name="epassword" id="inputid" placeholder="Re-Enter Password" id='input_id'></div>
<div class="col-xs-3">
<div class="checkbox"><input type="checkbox"> Auto Generate</div>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-3">Date Of Birth:</div>
<div class="col-xs-5">
<div class="input-group date">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="date" class="form-control pull-right" name="edateofbirth" value="<?php echo $userdob; ?>" id="inputid">
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-3">Mobile Number:</div>
<div class="col-xs-5">
<input type="text" class="form-control" placeholder="Enter Mobile" name="emobile" value="<?php echo $usermobile; ?>" id="inputid">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-3">Address:</div>
<div class="col-xs-5">
<textarea class="form-control" rows="3" placeholder="Enter Address" name="epresentaddress" value="<?php echo $useraddress; ?>" id="inputid"></textarea>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-3">Proof:</div>
<div class="col-xs-5">
<input type="text" class="form-control" placeholder="Enter Proof" name="edrivinglicense" value="<?php echo $userproof; ?>" id="inputid">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-3"></div>
<div class="col-xs-5">
<input type="submit" name="update" value="Update" id="inputid1" />
</div>
</div>
</div>
</form>
</div>
<?php } } ?>
Please help me with proper guidance where am i stuck here or i am making mistake
as per your code you put one condition i.e.
if(isset($_GET['id']))
{
.....
}
but in html form you are not pass any id field add id field and try your condition will verify and update will work.
just add one field like below.. remaining is same.
<form action="UPDATE.php?id=<?php echo $id; ?>" method="post" name="insertform">
<input type="hidden" name="id" value="<?php echo $id; ?>" >
...............
.................
</form>
Note: In HTML page id of field should be unique.

Editing via function call PHP

I am wrapping functions in php pages in the functions.php and to access these pages, i put an action and a value in the url. I also have a function_calls.php which requests the action and its value and passes it to a switch case which calls the appropriate function. The problem i have is that i case i want to edit a field . I dont have an appropriate case(for the switch) which i want to look something like admin.php?action=edit?id=some_id.
function_calls.php
<?php
require_once "functions.php";
if (isset($_REQUEST['action'])) {
$option = $_REQUEST['action'];
echo $option;
switch ($option) {
case "complaints":
complaint();
break;
case "users":
users();
break;
case "officers":
officers();
break;
case "register_officer":
register_officer();
break;
case "register_student":
register_student();
break;
case "add_event":
add_event();
break;
default:
complaint();
break;
}
} else {
echo '<div class="jumbotron">
<h1>Welcome To The Administration Panel </h1>
<p>You can manage accounts and view the complaints here.</p>
</div>';
}
functions.php
<?php
include_once "include/db_connect.php";
function register_student()
{
?>
<section>
<div class="row">
<div class="col-md-7 col-md-offset-1">
<form class="" method="post" action="">
<div class="row">
<div class="col-md-6 ">
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" placeholder="Firstname" name="firstname" required=""
class="form-control">
</div>
</div>
<div class="col-md-6">
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" placeholder="Lastname" name="lasttname" required=""
class="form-control">
</div>
</div>
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
<input type="text" placeholder="Email" name="email" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" placeholder="Registration Number" name="reg_no" required=""
class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-phone"></i></span>
<input type="text" placeholder="Phone" name="phone" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
<input type="password" placeholder="Password" name="password" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
<input type="password" placeholder="Confirm Password" name="conf_password" required=""
class="form-control">
</div>
<div class="row">
<!--<div class="col-md-6 checkbox">
<label><input type="checkbox">Remember me</label>
</div>-->
<div class="col-md-12">
<button class="btn btn-success btn-block pull-right" type="submit" name="register">Register
Student
</button>
</div>
</div>
</form>
</div>
</div>
</section>
<?php
}
function register_officer()
{
?>
<section>
<div class="row">
<div class="col-md-7 col-md-offset-1">
<form class="" method="post" action="register.php">
<div class="row">
<div class="col-md-6 ">
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" placeholder="Firstname" name="firstname" required=""
class="form-control">
</div>
</div>
<div class="col-md-6">
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" placeholder="Lastname" name="lastname" required=""
class="form-control">
</div>
</div>
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
<input type="text" placeholder="Email" name="email" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" placeholder="Rank" name="rank" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-phone"></i></span>
<input type="text" placeholder="Phone" name="phone" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
<input type="password" placeholder="Password" name="password" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
<input type="password" placeholder="Confirm Password" name="conf_password" required=""
class="form-control">
</div>
<div class="row">
<!--<div class="col-md-6 checkbox">
<label><input type="checkbox">Remember me</label>
</div>-->
<div class="col-md-12">
<button class="btn btn-success btn-block pull-right" type="submit" name="register_officer">
Register Officer
</button>
</div>
</div>
</form>
</div>
</div>
</section>
<?php
}
This would be a bit more elegant solution than yours:
<?php
require_once 'functions.php';
if (isset($_GET['action'])) {
$option = $_GET['action'];
echo $option;
if(in_array($option, get_defined_functions()['user']) === true) {
call_user_func($option);
} else {
complaint();
}
} else {
echo '<div class="jumbotron">
<h1>Welcome To The Administration Panel </h1>
<p>You can manage accounts and view the complaints here.</p>
</div>';
}
So then you can define a function edit() which will be automatically called by the call_user_func without altering the switch each time you add a new function.

Categories