Getting error on updating multiple rows using loop in codeigniter - php

When i am try to update details using for loop it is updated as a empty(Null) to refer columns.
Below is my code please help me what wrong with my logic.
View Code
The No. of text fields are going to generate depends on no. of values present in table. It is executing in foreach loop
<form method="post" action="<?php echo site_url('Home/advisor_update'); ?>"
<?php
if ($advisor_emp->num_rows()>0 )
{
$i=1;
foreach($advisor_emp->result() as $data)
{
$eid = $data->id;
$cn = $data->company_name;
$fd = $data->from_date;
$td = $data->to_date;
$tb = $data->type_of_buisness;
$c1 = $data->company_addres_lane_1;
$c2 = $data->company_addres_lane_2;
$cc = $data->c_city;
$cp = $data->c_pincode;
$cs = $data->c_state;
$cun = $data->c_country; ?>
<div class="col-md-6">
<div class="form-group">
<input type="" name="eid[]" class="form-control" value="<?php echo $eid; ?>">
</div>
<div class="col-md-12">
<div class="form-group">
<label>Previous Employer</label>
<input type="text" class="form-control" name="pcmp" value="<?php echo $cn; ?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>From</label>
<input type="text" name="pcmpfrom" class="form-control" value="<?php echo $fd ; ?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>To</label>
<input type="text" name="pcmpto" class="form-control" value="<?php echo $td ; ?>">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label>Designation</label>
<input type="text" name="pcmpdesi" class="form-control" value="<?php echo $tb;?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Company Address Line 1</label>
<input type="text" name="pcmpadr1[]" class="form-control" value="<?php echo $c1;?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Company Address Line 2</label>
<input type="text" name="pcmpadr2" class="form-control" value="<?php echo $c2;?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>City</label>
<input type="text" name="pcmpcit" class="form-control" value="<?php echo $cc;?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Pin Code</label>
<input type="text" name="pcmppin[]" class="form-control" value="<?php echo $cp;?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>State</label>
<input type="text" name="pcmpstat[]" class="form-control" value="<?php echo $cs; ?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Country</label>
<input type="text" name="pcmpcun[]" class="form-control" value="<?php echo $cun; ?>">
</div>
</div>
</div>
<?php
$i++;
}
}
?>
<div class="col-md-12"
<input type="submit" class="btn btn-primary" name="advisor_update" value="Update" >
</div>
</form>
Here is my Controller
In controller i'm goin to getting data from the view using for loop and sending recieved data to modal.
if ($this->input->post('advisor_update'))
{
$emp_his_id = $this->input->post('eid');
$count_eid = count($emp_his_id);
for($i=0;$i<$count_eid;$i++)
{
$emp_his_pk = $emp_his_id[$i];
$inserte['company_name']= $this->input->post('cn');
$inserte['from_date']= $this->input->post('fd');
$inserte['to_date']= $this->input->post('td');
$inserte['type_of_buisness']= $this->input->post('tb');
$inserte['company_addres_lane_1']= $this->input->post('c1');
$inserte['company_addres_lane_2']= $this->input->post('c2');
$inserte['c_city']= $this->input->post('cc');
$inserte['c_pincode']= $this->input->post('cp');
$inserte['updated_on'] = date("Y-m-d");
$up_emp_history=$this->Frontend_model->update_employe($inserte=array(),$emp_his_pk);
}
}
Here is my Modal
function update_employe($inserte=array(),$emp_his_pk)
{
$this->db->where('id',$emp_his_pk);
$result=$this->db->update("is_employment", $inserte);
return $result;
}

View Code
I have change your view codes input name
<form method="post" action="<?php echo site_url('Home/advisor_update'); ?>" >
<?php
if ($advisor_emp->num_rows()>0 )
{
foreach($advisor_emp->result() as $data)
{
$eid = $data->id;
$cn = $data->company_name;
$fd = $data->from_date;
$td = $data->to_date;
$tb = $data->type_of_buisness;
$c1 = $data->company_addres_lane_1;
$c2 = $data->company_addres_lane_2;
$cc = $data->c_city;
$cp = $data->c_pincode;
$cs = $data->c_state;
$cun = $data->c_country; ?>
<div class="col-md-6">
<div class="form-group">
<input type="" name="eid[]" class="form-control" value="<?php echo $eid; ?>">
</div>
<div class="col-md-12">
<div class="form-group">
<label>Previous Employer</label>
<input type="text" class="form-control" name="cn[]" value="<?php echo $cn; ?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>From</label>
<input type="text" name="fd[]" class="form-control" value="<?php echo $fd ; ?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>To</label>
<input type="text" name="td[]" class="form-control" value="<?php echo $td ; ?>">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label>Designation</label>
<input type="text" name="tb[]" class="form-control" value="<?php echo $tb;?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Company Address Line 1</label>
<input type="text" name="c1[]" class="form-control" value="<?php echo $c1;?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Company Address Line 2</label>
<input type="text" name="c2[]" class="form-control" value="<?php echo $c2;?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>City</label>
<input type="text" name="cc[]" class="form-control" value="<?php echo $cc;?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Pin Code</label>
<input type="text" name="cp[]" class="form-control" value="<?php echo $cp;?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>State</label>
<input type="text" name="cs[]" class="form-control" value="<?php echo $cs; ?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Country</label>
<input type="text" name="cun[]" class="form-control" value="<?php echo $cun; ?>">
</div>
</div>
</div>
<?php
}
}
?>
Controller Code
You have to run a foreach loop in controller.
if ($this->input->post('advisor_update'))
{
$emp_his_id = $this->input->post('eid');
$cn = $this->input->post('cn');
$fd = $this->input->post('fd');
$td = $this->input->post('td');
$td = $this->input->post('tb');
$c1 = $this->input->post('c1');
$c2 = $this->input->post('c2');
$cc = $this->input->post('cc');
$cp = $this->input->post('cp');
foreach($emp_his_id as $key => $eid)
{
$emp_his_pk = $eid;
$inserte = array();
$inserte['company_name']= $cn[$key];
$inserte['from_date']= $fd[$key];
$inserte['to_date']= $td[$key];
$inserte['type_of_buisness']= $tb[$key];
$inserte['company_addres_lane_1']= $c1[$key];
$inserte['company_addres_lane_2']= $c2[$key];
$inserte['c_city']= $cc[$key];
$inserte['c_pincode']= $cp[$key];
$inserte['updated_on'] = date("Y-m-d");
$up_emp_history=$this->Frontend_model->update_employe($inserte=array(),$emp_his_pk);
}
}
Hope This works for you

Related

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.

Data from row into no php-site for edit

I have a problem with my php-code. On the first site is a list with all the data. The table of the data is correctly displayed. In the last column of the table is a link placed to the next page which should hand over the id of the row.
Here's the link:
print 'Ändern';
But I can't now get the data into the input fields for edit. The form show up correct, but i have in every input field this error:
Warning: Illegal string offset 'vorname' in /home_pr5/d/e/deniseli.ch/htdocs/www.deniseli.ch/T .... tor/editsr.php on line 130S
Here's the editsr.php:
<?php
session_start();
require_once("inc/config.inc.php");
require_once("inc/functions.inc.php");
$id = $_GET['id'];
$statement = $pdo->prepare("SELECT * FROM users WHERE id = $id");
$result = $statement->execute(array('id' => ['id']));
$user = $statement->fetch();
include("templates/header.inc.php");
if(isset($_GET['save'])) {
$save = $_GET['save'];
if($save == 'personal_data') {
$vorname = trim($_POST['vorname']);
$nachname = trim($_POST['nachname']);
$adresse = trim($_POST['adresse']);
$plz = trim($_POST['plz']);
$ort = trim($_POST['ort']);
$geburtstag = trim($_POST['geburtstag']);
$handy = trim($_POST['handy']);
$liga = trim($_POST['liga']);
$verein = trim($_POST['verein']);
$bank = trim($_POST['bank']);
$iban = trim($_POST['iban']);
if($vorname == "" || $nachname == "" || $adresse == "" || $plz == "" || $ort == "" || $handy == "" || $liga == "" || $verein == "") {
$error_msg = "Bitte alle Angaben ausfüllen.";
} else {
$statement = $pdo->prepare("UPDATE users SET vorname = :vorname, nachname = :nachname, adresse = :adresse, plz = :plz, ort = :ort, geburtstag = :geburtstag, handy = :handy, liga = :liga, verein = :verein, bank = :bank, iban = :iban, id = :id, updated_at=NOW() WHERE id = $id");
$result = $statement->execute(array('vorname' => $vorname, 'nachname'=> $nachname,'adresse' => $adresse, 'plz' => $plz, 'ort' => $ort, 'geburtstag' => $geburtstag, 'handy' => $handy, 'liga' => $liga, 'verein' => $verein,'bank' => $bank, 'iban' => $iban, 'id' => $user['id'] ));
$success_msg = "Daten erfolgreich gespeichert.";
}
} else if($save == 'email') {
$passwort = $_POST['passwort'];
$email = trim($_POST['email']);
$email2 = trim($_POST['email2']);
if($email != $email2) {
$error_msg = "Die eingegebenen E-Mail-Adressen stimmten nicht überein.";
} else if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error_msg = "Bitte eine gültige E-Mail-Adresse eingeben.";
} else if(!password_verify($passwort, $user['passwort'])) {
$error_msg = "Bitte korrektes Passwort eingeben.";
} else {
$statement = $pdo->prepare("UPDATE users SET email = :email WHERE id = $id");
$result = $statement->execute(array('email' => $email));
$success_msg = "E-Mail-Adresse erfolgreich gespeichert.";
}
} else if($save == 'passwort') {
$passwortAlt = $_POST['passwortAlt'];
$passwortNeu = trim($_POST['passwortNeu']);
$passwortNeu2 = trim($_POST['passwortNeu2']);
if($passwortNeu != $passwortNeu2) {
$error_msg = "Die eingegebenen Passwörter stimmten nicht überein.";
} else if($passwortNeu == "") {
$error_msg = "Das Passwort darf nicht leer sein.";
} else if(!password_verify($passwortAlt, $user['passwort'])) {
$error_msg = "Bitte korrektes Passwort eingeben.";
} else {
$passwort_hash = password_hash($passwortNeu, PASSWORD_DEFAULT);
$statement = $pdo->prepare("UPDATE users SET passwort = :passwort WHERE id = $id");
$result = $statement->execute(array('passwort' => $passwort_hash));
$success_msg = "Passwort erfolgreich gespeichert.";
}
}
}
?>
<div class="container main-container">
<h1>Schiedsrichter Profil bearbeiten</h1>
<?php
if(isset($success_msg) && !empty($success_msg)):
?>
<div class="alert alert-success">
×
<?php echo $success_msg; ?>
</div>
<?php
endif;
?>
<?php
if(isset($error_msg) && !empty($error_msg)):
?>
<div class="alert alert-danger">
×
<?php echo $error_msg; ?>
</div>
<?php
endif;
?>
<div>
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">Übersicht</li>
<li role="presentation">Persönliche Daten</li>
<li role="presentation">E-Mail</li>
<li role="presentation">Passwort</li>
</ul>
<!-- Übersicht-->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="home">
<br>
<form action="?save=personal_data&id=<?php echo $_GET['id'] ?>" method="post" class="form-horizontal">
<div class="form-group">
<label for=inputVorname class="col-sm-2 control-label">Vorname</label>
<div class="col-sm-10">
<input class="form-control" id="inputVorname" name="vorname" type="text" value="<?php echo htmlentities($user['vorname']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputNachname" class="col-sm-2 control-label">Nachname</label>
<div class="col-sm-10">
<input class="form-control" id="inputNachname" name="nachname" type="text" value="<?php echo htmlentities($user['nachname']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputAdresse" class="col-sm-2 control-label">Adresse</label>
<div class="col-sm-10">
<input class="form-control" id="inputAdresse" name="adresse" type="text" value="<?php echo htmlentities($user['adresse']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputPLZ" class="col-sm-2 control-label">PLZ</label>
<div class="col-sm-10">
<input class="form-control" id="inputPLZ" name="plz" type="text" value="<?php echo htmlentities($user['plz']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputOrt" class="col-sm-2 control-label">Ort</label>
<div class="col-sm-10">
<input class="form-control" id="inputOrt" name="ort" type="text" value="<?php echo htmlentities($user['ort']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputGeburtstag" class="col-sm-2 control-label">Geburtsdatum</label>
<div class="col-sm-10">
<input class="form-control" id="inputGeburtstag" name="geburtstag" type="text" value="<?php echo htmlentities($user['geburtstag']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputEmail" class="col-sm-2 control-label">E-Mail</label>
<div class="col-sm-10">
<input class="form-control" id="inputEmail" name="email" type="email" value="<?php echo htmlentities($user['email']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputHandy" class="col-sm-2 control-label">Handy</label>
<div class="col-sm-10">
<input class="form-control" id="inputHandy" name="handy" type="text" value="<?php echo htmlentities($user['handy']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputLiga" class="col-sm-2 control-label">Liga</label>
<div class="col-sm-10">
<input class="form-control" id="inputLiga" name="liga" type="text" value="<?php echo htmlentities($user['liga']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputVerein" class="col-sm-2 control-label">Verein</label>
<div class="col-sm-10">
<input class="form-control" id="inputVerein" name="verein" type="text" value="<?php echo htmlentities($user['verein']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputBank" class="col-sm-2 control-label">Bankname</label>
<div class="col-sm-10">
<input class="form-control" id="inputBank" name="bank" type="text" value="<?php echo htmlentities($user['bank']); ?>" readonly>
</div>
</div>
<div class="form-group">
<label for="inputIban" class="col-sm-2 control-label">IBAN</label>
<div class="col-sm-10">
<input class="form-control" id="inputIban" name="iban" type="text" value="<?php echo htmlentities($user['iban']); ?>" readonly>
</div>
</div>
</form>
</div>
<!-- Persönliche Daten-->
<div role="tabpanel" class="tab-pane" id="data">
<br>
<form action="?save=personal_data&id=<?php echo $_GET['id'] ?>" method="post" class="form-horizontal">
<div class="form-group">
<label for="inputVorname" class="col-sm-2 control-label">Vorname</label>
<div class="col-sm-10">
<input class="form-control" id="inputVorname" name="vorname" type="text" value="<?php echo htmlentities($user['vorname']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputNachname" class="col-sm-2 control-label">Nachname</label>
<div class="col-sm-10">
<input class="form-control" id="inputNachname" name="nachname" type="text" value="<?php echo htmlentities($user['nachname']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputAdresse" class="col-sm-2 control-label">Adresse</label>
<div class="col-sm-10">
<input class="form-control" id="inputAdresse" name="adresse" type="text" value="<?php echo htmlentities($user['adresse']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputPLZ" class="col-sm-2 control-label">PLZ</label>
<div class="col-sm-10">
<input class="form-control" id="inputPLZ" name="plz" type="text" value="<?php echo htmlentities($user['plz']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputOrt" class="col-sm-2 control-label">Ort</label>
<div class="col-sm-10">
<input class="form-control" id="inputOrt" name="ort" type="text" value="<?php echo htmlentities($user['ort']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputGeburtstag" class="col-sm-2 control-label">Geburtsdatum</label>
<div class="col-sm-10">
<input class="form-control" id="inputGeburtstag" name="geburtstag" type="text" value="<?php echo htmlentities($user['geburtstag']); ?>" placeholder="01.01.2000">
</div>
</div>
<div class="form-group">
<label for="inputHandy" class="col-sm-2 control-label">Handy</label>
<div class="col-sm-10">
<input class="form-control" id="inputHandy" name="handy" type="text" value="<?php echo htmlentities($user['handy']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputLiga" class="col-sm-2 control-label">Liga</label>
<div class="col-sm-10">
<input class="form-control" id="inputLiga" name="liga" type="text" value="<?php echo htmlentities($user['liga']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputVerein" class="col-sm-2 control-label">Verein</label>
<div class="col-sm-10">
<input class="form-control" id="inputVerein" name="verein" type="text" value="<?php echo htmlentities($user['verein']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputBank" class="col-sm-2 control-label">Bankname</label>
<div class="col-sm-10">
<input class="form-control" id="inputBank" name="bank" type="text" value="<?php echo htmlentities($user['bank']); ?>" placeholder="Postfinance">
</div>
</div>
<div class="form-group">
<label for="inputIban" class="col-sm-2 control-label">IBAN</label>
<div class="col-sm-10">
<input class="form-control" id="inputIban" name="iban" type="text" value="<?php echo htmlentities($user['iban']); ?>" placeholder="CHxx xxxx xxxx xxxx xxxx x">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Speichern</button>
<a class="btn btn-danger" href='internal.php'>Abbrechen</a>
</div>
</div>
</form>
</div>
<!-- Änderung der E-Mail-Adresse -->
<div role="tabpanel" class="tab-pane" id="email">
<br>
<p>Zum Änderen deiner E-Mail-Adresse gib bitte dein aktuelles Passwort sowie die neue E-Mail-Adresse ein.</p>
<form action="?save=email&id=<?php echo $_GET['id'] ?>" method="post" class="form-horizontal">
<div class="form-group">
<label for="inputPasswort" class="col-sm-2 control-label">Passwort</label>
<div class="col-sm-10">
<input class="form-control" id="inputPasswort" name="passwort" type="password" required>
</div>
</div>
<div class="form-group">
<label for="inputEmail" class="col-sm-2 control-label">E-Mail</label>
<div class="col-sm-10">
<input class="form-control" id="inputEmail" name="email" type="email" value="<?php echo htmlentities($user['email']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputEmail2" class="col-sm-2 control-label">E-Mail (wiederholen)</label>
<div class="col-sm-10">
<input class="form-control" id="inputEmail2" name="email2" type="email" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Speichern</button>
<a class="btn btn-danger" href='spielliste.php'>Abbrechen</a>
</div>
</div>
</form>
</div>
<!-- Änderung des Passworts -->
<div role="tabpanel" class="tab-pane" id="passwort">
<br>
<p>Zum Änderen deines Passworts gib bitte dein aktuelles Passwort sowie das neue Passwort ein.</p>
<form action="?save=passwort&id=<?php echo $_GET['id'] ?>" method="post" class="form-horizontal">
<div class="form-group">
<label for="inputPasswort" class="col-sm-2 control-label">Altes Passwort</label>
<div class="col-sm-10">
<input class="form-control" id="inputPasswort" name="passwortAlt" type="password" required>
</div>
</div>
<div class="form-group">
<label for="inputPasswortNeu" class="col-sm-2 control-label">Neues Passwort</label>
<div class="col-sm-10">
<input class="form-control" id="inputPasswortNeu" name="passwortNeu" type="password" required>
</div>
</div>
<div class="form-group">
<label for="inputPasswortNeu2" class="col-sm-2 control-label">Neues Passwort (wiederholen)</label>
<div class="col-sm-10">
<input class="form-control" id="inputPasswortNeu2" name="passwortNeu2" type="password" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Speichern</button>
<a class="btn btn-danger" href='spielliste.php'>Abbrechen</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php
include("templates/footer.inc.php")
?>
UPDATE: new code editsr.php. Works fine with the tabs, only the changes displayed after refresh the site.
Look at your code carefully
on the top you are using the $user variable like below
$id = $_GET['id'];
$statement = $pdo->prepare("SELECT * FROM users WHERE id = :id");
$result = $statement->execute(array('id' => ['id']));
$user = $statement->fetch(); // here
and again on the bottom of php code you are using $user variable like below
$id = $_GET['id'];
$user = "SELECT * FROM users WHERE id = :id"; // here
?>
on the input you are trying to get like htmlentities($user['vorname']);
<div class="form-group">
<label for=inputVorname class="col-sm-2 control-label">Vorname</label>
<div class="col-sm-10">
<input class="form-control" id="inputVorname" name="vorname" type="text" value="<?php echo htmlentities($user['vorname']); ?>" readonly>
</div>
</div>
that's the problem of error in every input :)
New Code with only one form:
<?php
session_start();
require_once("inc/config.inc.php");
require_once("inc/functions.inc.php");
$id = $_GET['id'];
$statement = $pdo->prepare("SELECT * FROM users WHERE id = $id");
$result = $statement->execute(array('id' => ['id']));
$user = $statement->fetch();
include("templates/header.inc.php");
if(isset($_GET['save'])) {
$save = $_GET['save'];
if($save == 'personal_data') {
$vorname = trim($_POST['vorname']);
$nachname = trim($_POST['nachname']);
$adresse = trim($_POST['adresse']);
$plz = trim($_POST['plz']);
$ort = trim($_POST['ort']);
$geburtstag = trim($_POST['geburtstag']);
$handy = trim($_POST['handy']);
$email = trim($_POST['email']);
$liga = trim($_POST['liga']);
$verein = trim($_POST['verein']);
$bank = trim($_POST['bank']);
$iban = trim($_POST['iban']);
$passwortNeu = trim($_POST['passwortNeu']);
if($vorname == "" || $nachname == "" || $adresse == "" || $plz == "" || $ort == "" || $handy == "" || $liga == "" || $verein == "" || $email == "" || $passwortNeu == "" ){
$error_msg = "Bitte alle Angaben ausfüllen.";
} else {
$passwort_hash = password_hash($passwortNeu, PASSWORD_DEFAULT);
$statement = $pdo->prepare("UPDATE users SET vorname = :vorname, nachname = :nachname, adresse = :adresse, plz = :plz, ort = :ort, geburtstag = :geburtstag, handy = :handy, liga = :liga, verein = :verein, bank = :bank, iban = :iban, passwort = :passwort, email = :email, updated_at=NOW() WHERE id = $id");
$result = $statement->execute(array('vorname' => $vorname, 'nachname'=> $nachname,'adresse' => $adresse, 'plz' => $plz, 'ort' => $ort, 'geburtstag' => $geburtstag, 'handy' => $handy, 'liga' => $liga, 'verein' => $verein,'bank' => $bank, 'iban' => $iban, 'passwort' => $passwort_hash, 'email' => $email));
$success_msg = "Daten erfolgreich gespeichert.";
}
}
}
?>
<div class="container main-container">
<h1>Schiedsrichter Profil bearbeiten</h1>
<?php
if(isset($success_msg) && !empty($success_msg)):
?>
<div class="alert alert-success">
×
<?php echo $success_msg; ?>
</div>
<?php
endif;
?>
<?php
if(isset($error_msg) && !empty($error_msg)):
?>
<div class="alert alert-danger">
×
<?php echo $error_msg; ?>
</div>
<?php
endif;
?>
<div>
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">Persönliche Daten</li>
</ul>
<!-- Persönliche Daten-->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="data">
<br>
<form action="?save=personal_data" method="post" class="form-horizontal">
<div class="form-group">
<label for="inputVorname" class="col-sm-2 control-label">Vorname</label>
<div class="col-sm-10">
<input class="form-control" id="inputVorname" name="vorname" type="text" value="<?php echo htmlentities($user['vorname']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputNachname" class="col-sm-2 control-label">Nachname</label>
<div class="col-sm-10">
<input class="form-control" id="inputNachname" name="nachname" type="text" value="<?php echo htmlentities($user['nachname']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputAdresse" class="col-sm-2 control-label">Adresse</label>
<div class="col-sm-10">
<input class="form-control" id="inputAdresse" name="adresse" type="text" value="<?php echo htmlentities($user['adresse']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputPLZ" class="col-sm-2 control-label">PLZ</label>
<div class="col-sm-10">
<input class="form-control" id="inputPLZ" name="plz" type="text" value="<?php echo htmlentities($user['plz']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputOrt" class="col-sm-2 control-label">Ort</label>
<div class="col-sm-10">
<input class="form-control" id="inputOrt" name="ort" type="text" value="<?php echo htmlentities($user['ort']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputGeburtstag" class="col-sm-2 control-label">Geburtsdatum</label>
<div class="col-sm-10">
<input class="form-control" id="inputGeburtstag" name="geburtstag" type="text" value="<?php echo htmlentities($user['geburtstag']); ?>" placeholder="01.01.2000">
</div>
</div>
<div class="form-group">
<label for="inputHandy" class="col-sm-2 control-label">Handy</label>
<div class="col-sm-10">
<input class="form-control" id="inputHandy" name="handy" type="text" value="<?php echo htmlentities($user['handy']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputEmail" class="col-sm-2 control-label">E-Mail</label>
<div class="col-sm-10">
<input class="form-control" id="inputEmail" name="email" type="email" value="<?php echo htmlentities($user['email']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputLiga" class="col-sm-2 control-label">Liga</label>
<div class="col-sm-10">
<input class="form-control" id="inputLiga" name="liga" type="text" value="<?php echo htmlentities($user['liga']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputVerein" class="col-sm-2 control-label">Verein</label>
<div class="col-sm-10">
<input class="form-control" id="inputVerein" name="verein" type="text" value="<?php echo htmlentities($user['verein']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputBank" class="col-sm-2 control-label">Bankname</label>
<div class="col-sm-10">
<input class="form-control" id="inputBank" name="bank" type="text" value="<?php echo htmlentities($user['bank']); ?>" placeholder="Postfinance">
</div>
</div>
<div class="form-group">
<label for="inputIban" class="col-sm-2 control-label">IBAN</label>
<div class="col-sm-10">
<input class="form-control" id="inputIban" name="iban" type="text" value="<?php echo htmlentities($user['iban']); ?>" placeholder="CHxx xxxx xxxx xxxx xxxx x">
</div>
</div>
<div class="form-group">
<label for="inputPasswortNeu" class="col-sm-2 control-label">Neues Passwort</label>
<div class="col-sm-10">
<input class="form-control" id="inputPasswortNeu" name="passwortNeu" type="password" value="<?php echo htmlentities($user['passwort']); ?>" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Speichern</button>
<a class="btn btn-danger" href='internal.php'>Abbrechen</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php
include("templates/footer.inc.php")
?>

Calling controllers different methods from view page using codeigniter

I am working on codeigniter project in which viwe page having textboxes, radio buttons and button.I fetched textbox values from database and manually enter from date and to date then by clicking on save button insert query gets empty values because in controller i called all functions serially in index function.What is the best solution to call controller methods on each event of view page?
leave_appl_view.php
<form action="leave_apply_control/index" method="post" id="myForm">
<div class="row">
<div class="col-md-3">
<div class="form-group label-floating">
<label class="control-label">Emp ID</label>
<?php if(!empty($emp_leave))
{
foreach ($emp_leave as $liv)
{ ?>
<input type="text" class="form-control" name="id" value="<?php echo $liv->employee_id ?>" >
</div>
</div>
<div class="col-md-4">
<div class="form-group label-floating">
<label class="control-label">Employee Name</label>
<input type="text" class="form-control" name="empname" id="empname" value="<?php echo $liv->employee_name ?>" >
</div>
</div>
<div class="col-md-4">
<div class="form-group label-floating">
<label class="control-label">Email address</label>
<input type="email" class="form-control" name="empmail" id="empmail" value="<?php echo $liv->email ?>" >
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group label-floating">
<label class="control-label">Leave type: </label>
<input type="radio" id="half" name="type" onclick="Checkradiobutton()" value="half"> Half Day
<input type="radio" id="full" name="type" onclick="Checkbutton()" value="full" Checked> Full Day
</div>
</div>
<div class="col-md-3">
<div class="form-group label-floating" id="frm_dt">
<label class="control-label">From Date: </label>
<input type="text" class="form-control" id="datepicker1" name="from" ></p>
</div>
</div>
<div class="col-md-3">
<div class="form-group label-floating" id="to_dt">
<label class="control-label">To Date: </label>
<input type="text" class="form-control" id="datepicker2" name="to" ></p>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group label-floating">
<label class="control-label">Balance Leaves</label>
<input type="text" class="form-control" name="bal_leave" value="<?php echo $liv->balanced_leaves ?>" >
</div>
<?php }
}
?>
</div>
<div class="col-md-3">
<div class="form-group label-floating">
<label class="control-label">Applied Leaves</label>
<input type="text" class="form-control" name="totaldays" id="totaldays" readonly>
</div>
</div>
<div class="col-md-3">
<div class="form-group label-floating">
<label class="control-label">Applied Date</label>
<input type="text" class="form-control" name="todayDate" id="todayDate" value="<?php echo date("d/m/Y"); ?>" readonly>
</div>
</div>
</div>
<div class="row">
<div class="col-md-7">
<div class="form-group label-floating">
<label class="control-label">Reason </label>
<TEXTAREA class="form-control" id="reason" name="reason"> </TEXTAREA>
</div>
</div>
</div>
<button type="submit" class="btn btn-primary" id="submit" name="submit" onclick="<?php // echo base_url() ?>leave_apply_control/save_data">Apply</button>
<button type="reset" class="btn btn-primary" onclick="<?php echo base_url();?>leave_apply_control" >Reset</button>
</form>
leave_Apply_control.php
<?php
class leave_apply_control extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library(array('session', 'form_validation'));
$this->load->library('calendar');
$this->load->database();
$this->load->model('user_model');
$this->load->helper('date');
}//contruct close
function index()
{
$id=$this->session->userdata('id');
$data['foren_id'] = $this -> user_model -> get_emp_id($id);
foreach($data['foren_id'] as $fk)
{
//echo "////control page fk is ".$fk->emp_id;
}
$data2['emp_leave'] = $this->user_model->get_leave_count($fk->emp_id);
$this->load->view('leave_application',$data2);
$this->save_data();
}
public function save_data()
{
$fd = date('Y-m-d',strtotime($this->input->post('from')));
$td = date('Y-m-d',strtotime($this->input->post('to')));
$data = array(
'employee_id' => $this->input->post('id'),
'emp_name' => $this->input->post('empname'),
'leave_from' => $fd,
'leave_to' => $td,
'no_of_days' => $this->input->post('totaldays'),
'applied_date' => date('Y-m-d H:i:s'),
'reason' => $this->input->post('reason'),
'mail' => $this->input->post('empmail'),
'leave_type' => $this->input->post('type'),
'balance_leaves' => $this->input->post('bal_leave'),
'status' => 1,
);
$this->user_model->insert_leave($data);
}
}

Php multipart/form-data insert into database script not working

I'm trying to allow user to update a database of products through form but upon submit nothing happens... No errors are even fired. I have been trying to work this out for hours and maybe my eyes are getting too tire because I can't see what's wrong...
form.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once $_SERVER['DOCUMENT_ROOT'].'/ecommerce/core/init.php';
include 'includes/header.php';
if(isset($_GET['add'])){
$parentQuery = $db->query("SELECT * FROM categories WHERE parent= 0" );
if (isset($_POST['submit'])) {
if(isset($_POST['prod_name']))
{
$prod_name = sanitize($_POST)['prod_name'];
}
if(isset($_POST['child']))
{
$categories = sanitize($_POST)['child'];
}
if(isset($_POST['price']))
{
$price = sanitize($_POST)['price'];
}
if(isset($_POST['list_price']))
{
$prod_name = sanitize($_POST)['list_price'];
}
if(isset($_POST['prod_width']))
{
$prod_width = sanitize($_POST)['prod_width'];
}
if(isset($_POST['prod_depth']))
{
$prod_depth = sanitize($_POST)['prod_depth'];
}
if(isset($_POST['prod_height']))
{
$prod_height = sanitize($_POST)['prod_height'];
}
if(isset($_POST['prod_material']))
{
$prod_material = sanitize($_POST)['prod_material'];
}
if(isset($_POST['quantity']))
{
$quantity = sanitize($_POST)['quantity'];
}
if(isset($_POST['care_instructions']))
{
$care_instructions = sanitize($_POST)['care_instructions'];
}
if(isset($_POST['image_1']))
{
$image_1 = $_FILES['image_1'];
}
if(isset($_POST['image_2']))
{
$image_2 = $_FILES['image_2'];
}
if(isset($_POST['image_3']))
{
$image_3 = $_FILES['image_3'];
}
if(isset($_POST['image_4']))
{
$image_4 = $_FILES['image_4'];
}
if(isset($_POST['description']))
{
$description = sanitize($_POST)['description'];
} else {
$errors = array();
$required = array('prod_name','child','price','prod_width', 'prod_depth','prod_height', 'prod_material', 'quantity', 'description', 'care_instructions', 'image_1', 'image_2', 'image_3', 'image_4');
foreach ($required as $field) {
if ($_POST[$field] == '') {
$errors[] = 'All Fields With and Astrisk are required';
break; } else {
//upload file and insert into database
//move_uploaded_file($tmpLoc, $uploadPath);
$insertSql = "INSERT INTO `product` (`prod_name`,`child`,`price`,`list_price`,`prod_width`,`prod_depth`,`prod_height`, `prod_material`, `quantity`, `description`, `care_instructions`, `image_1`, `image_2`, `image_3`, `image_4`); VALUES ('$prod_name','$child','$price','$list_price','$prod_width', '$prod_depth','$prod_height', '$prod_material', '$quantity', '$description', '$care_instructions', '$image_1', '$image_2', '$image_3', '$image_4');";
$db->query($insertSql) or die(mysqli_error($db));
header('Location: products.php');}}}}?>
<form action="products.php?add=1" method="POST" enctype="multipart/form-data">
<div class='container_12'>
<div class="form-group col-md-3">
<label for="prod_name">Product Name*:</label>
<input type="text" name="prod_name" id="prod_name" class="form-control" value="<?=((isset($_POST['prod_name']))?sanitize($_POST['prod_name']):' ');?>">
</div>
<div class="form-group col-md-3">
<label for="parent">Parent Category*:</label>
<select class="form-control" id="parent" name="parent">
<option value=""<?=((isset($_POST['parent']) && $_POST['parent'] == '')?'selected':'');?>></option>
<?php while($parent = mysqli_fetch_assoc($parentQuery)): ?>
<option value=" <?=$parent['id'];?>"<?=((isset($_POST['parent']) && $_POST['parent'] == $parent['id'])?' select':'');?>><?=$parent['category_name'];?></option>
<?php endwhile; ?>
</select>
</div>
<div class='form-group col-md-3'>
<label for='child'>Second Category*:</label>
<select id='child' name='child' class='form-control'></select>
</div>
</div>
<div class='container_12'>
<div class='form-group col-md-3'>
<label for='list_price'>List Price(OPTIONAL): </label>
<input type="text" id="list_price" name="list_price" class="form-control" value="<?=((isset($_POST['list_price']))?sanitize($_POST['list_price']):'');?>">
</div>
<div class="form-group col-md-3">
<label for="price">Price*:</label>
<input type="text" id="price" name="price" class="form-control" value="<?=((isset($_POST['price']))?sanitize($_POST['price']):'');?>">
</div>
<div class='form-group col-md-3'>
<label for='prod_width'>Width* (in inches):</label>
<input type="text" id="prod_width" name="prod_width" class="form-control" value="<?=((isset($_POST['prod_width']))?sanitize($_POST['prod_width']):'');?>">
</div>
<div class='form-group col-md-3'>
<label for='prod_depth'>Height*(in inches):</label>
<input type="text" id="'prod_depth" name="'prod_depth" class="form-control" value="<?=((isset($_POST['prod_depth']))?sanitize($_POST['prod_depth']):'');?>">
</div>
</div>
<div class='container_12'>
<div class='form-group col-md-3'>
<label for='prod_height'>Depth*(in inches):</label>
<input type="text" id="prod_height" name="prod_height" class="form-control" value="<?=((isset($_POST['prod_height']))?sanitize($_POST['prod_height']):'');?>">
</div>
<div class='form-group col-md-3'>
<label for='prod_material'>Construction Material:</label>
<input type="text" id="prod_material" name="prod_material" class="form-control" value="<?=((isset($_POST['prod_material']))?sanitize($_POST['prod_material']):'');?>">
</div>
<div class='form-group col-md-6'>
<label>Quantity * :</label>
<input type="text" id="quantity" name="quantity" class="form-control" value="<?=((isset($_POST['quantity']))?sanitize($_POST['quantity']):'');?>">
</div>
</div>
<div class='container_12'>
<div class="form-group col-md-3"> <label for="image_1">Product Photo #1:</label>
<input type="file" name="image_1" id="image_1" class="form-control">
</div>
<div class="form-group col-md-3"> <label for="image_2">Product Photo #2:</label>
<input type="file" name="image_2" id="image_2" class="form-control">
</div>
<div class="form-group col-md-3"> <label for="image_3">Product Photo #3:</label>
<input type="file" name="image_3" id="image_3" class="form-control">
</div>
<div class="form-group col-md-3"> <label for="image_4">Product Photo#4:</label>
<input type="file" name="image_4" id="image_4" class="form-control">
</div>
</div>
<div class='container_12'>
<div class="form-group col-md-6">
<label for="description">Description:</label>
<textarea id="description" name="description" class="form-control" rows="6"><?=((isset($_POST['description']))?sanitize($_POST['description']):'');?></textarea>
</div>
<div class="form-group col-md-6">
<label for="care_instructions">Care Instructions*:</label>
<textarea id="care_instructions" name="care_instructions" class="form-control" rows="6"><?=((isset($_POST['care_instructions']))?sanitize($_POST['care_instructions']):'');?></textarea>
</div></div>
<div class='container_12'>
<div class="form-group pull-right">
<input type='submit' name='submit' value='Add Product' class='form-control btn-success pull-right'>
</div></div>
</form>

Can not get data from database in ECHO

My edit.php code is stated below, and this is what the outcome is: http://i.imgur.com/lt89Wi8.png
But what it is supposed to do is, get the information from the username - loggin_session, and show their server details , so they dont have to re-write everything.
see: http://i.imgur.com/fGEsXPq.png
<?php
$query = "SELECT id, username, name, url, banner, description, sponsor, votes FROM websites WHERE username = '$login_session'";
$result = mysql_query($query) OR die($mysql_error());
$num = mysql_num_rows($result);
if ($num < 1) {
$n = FALSE;
echo '<font color="red">You have no servers to edit, You can add one here</font><br />';
die();
} ?>
<form action="" method="post" name="join_form" class="form-horizontal" role="form" enctype="multipart/form-data" onSubmit="return checkform(this);">
<div class="form-group ">
<label for="join_email" class="col-md-1 control-label"><span class="required">*</span>Server Title</label>
<div class="col-md-5">
<input name="name" value="<?php echo $_POST['name']; ?>" class="form-control" placeholder="<?php echo ''.$row['name'].''?>" required>
</div>
</div>
<div class="form-group ">
<label for="join_password" class="col-md-1 control-label"><span class="required">*</span>Website URL</label>
<div class="col-md-5">
<input name="url" value="<?php if (isset($_POST['url'])) echo $_POST['url']; ?>" class="form-control" placeholder="<?php echo ''.$row['url'].''?>" required>
</div>
</div>
<div class="form-group ">
<label for="join_url" class="col-md-1 control-label"><span class="required">*</span>Banner URL</label>
<div class="col-md-5">
<input name="banner" value="<?php if (isset($_POST['banner'])) echo $_POST['banner']; ?>" class="form-control" type="text" placeholder="<?php echo ''.$row['banner'].''?>" required>
</div>
</div>
<div class="form-group ">
<label for="join_title" class="col-md-1 control-label"></label>
<div class="col-md-5"></div>
</div>
<div class="form-group ">
<label for="join_description" class="col-md-1 control-label"><span class="required">*</span>Descr..</label>
<div class="col-md-5">
<textarea cols="50" rows="5" value="<?php if(isset($_POST['description'])) echo $_POST['description']; ?>" name="description" id="description_size" class="form-control" placeholder="<?php echo ''.$row['description'].''?>" required></textarea>
</div>
</div>
<input type="submit" name="submit" value="Add" />
<input type="hidden" name="submitted" value="TRUE" />
</form>
$row is undefined in your code. It has to be
$row=mysql_fetch_assoc($result); // fetch it from the result set
How can I prevent SQL injection in PHP?
And what's up with that useless '' in every echo?
echo ''.$row['name'].''
^^ ^^
This is enough
echo $row['name'];

Categories