My Ajax script is not going to controller and data is not uploading.
Script is:
$("#update").click(function(event) {
/* Act on the event */
var chango = $("#update_form").serialize();
alert(chango);
$.ajax({
type:"POST",
url:"<?php echo base_url() ?>home/update_profile",
data:{id:id}
},
function(data) {
console.log(data);
list_user();
});
event.preventDefault();
});
and my controller is:
public function update_profile()
{
try {
$this->load->library('form_validation');
$this->form_validation->set_rules("fname", "First Name", 'required|alpha');
$this->form_validation->set_rules("lname", "Last Name", 'required|alpha');
$this->form_validation->set_rules("mobile", "Mobile", 'required');
$this->form_validation->set_rules("dob", "Date of Birth", 'required');
$this->form_validation->set_rules("gender", "Gender", 'required');
if ($this->form_validation->run()){
$this->load->model("user");
$data=array(
'fname' => $this->input->post('fname'),
'lname' => $this->input->post('lname'),
'mobile' => $this->input->post('mobile'),
'dob' => $this->input->post('dob'),
'gender' => $this->input->post('gender')
);
if ($this->input->post("update")) {
$this->user->update_data($data, $this->input->post("id"));
redirect(base_url() . "home/list_user");
}
}
else
{
}
}
catch(Exception $e) {
}
$this->load->view('middlepage/update_profile.php');
}
public function update()
{
$user_id = $this->uri->segment(3);
$this->load->model("user");
$data["user_data"] = $this->user->fetch_single_data($user_id);
$data["fetch_data"] = $this->user->fetch_data1();
$this->load->view("middlepage/update_profile", $data);
}
And my model is:
public function fetch_single_data($id)
{
$this->db->where("id", $id);
$query = $this->db->get("user");
return $query;
}
public function update_data($data, $id)
{
$this->db->where("id", $id);
return $this->db->update("user", $data);
}
And my view is:
<form method="post" id="update_form" enctype="multipart/form-data" novalidate="true">
<?php if(isset($user_data))
{
foreach ($user_data->result() as $row) {
?>
<div class="form-group valid-form">
<h4>First Name:</h4>
<input type="text" class="form-control" id="fname" name="fname" value="<?php echo $row->fname ; ?>">
<span class="text-danger"><?php echo form_error("fname");?></span>
</div><br>
<div class="form-group valid-form">
<h4>Last Name:</h4>
<input type="text" class="form-control" id="lname" name="lname" value="<?php echo $row->lname ; ?>">
<span class="text-danger"><?php echo form_error("lname");?></span>
</div><br>
<div class="form-group valid-form">
<h4>Mobile:</h4>
<input type="text" class="form-control" id="mobile" name="mobile" value="<?php echo $row->mobile ; ?>">
<span class="text-danger"><?php echo form_error("mobile");?></span>
</div><br>
<div class="form-group valid-form">
<h4>Date of Birth:</h4>
<input type="date" class="form-control" min="1984-01-01" max="2005-12-31" id="dob" name="dob" value="<?php echo $row->dob ; ?>">
<span class="text-danger"><?php echo form_error("dob");?></span>
</div><br>
<div class="form-group">
<h4>Gender</h4>
<div class="radio">
<label>
<input type="radio" name="gender" id="male" value="male"<?php if($row->gender == 'male') echo "checked"; ?>><span style="font-weight: bolder; font-size: 15px;">Male</span>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="gender" id="female" value="female"<?php if($row->gender == 'female') echo "checked"; ?>><span style="font-weight: bolder; font-size: 15px;">Female</span>
</label>
</div>
<span class="text-danger"><?php echo form_error("gender");?></span>
</div><br>
<div class="form-group">
<input type="hidden" name="id" value="<?php echo $row->id ?>">
<input type="submit" name="update" id="update" value="Update" class="btn btn-primary">
</div>
<?php
}
}
?>
</form>
i can't update data in database and it is not going to list table
ajax function is not working and not going to codeigniter's controller
while is try this type of similar code to submit it is work perfectly
From where you get id which you pass as data in id field
$.ajax({
type:"POST",
url:"<?php echo base_url() ?>home/update_profile",
data:{id:id} <--
},
Related
I have a page for adding scores of students in a school. After submitting scores of the students, the input boxes are repopulated with the results from the database.
This was done so that
Teachers who are unable to complete adding scores for students can come back and continue from where they left off.
If an edit is to be made, teachers will know where and what to be edited.
And generally for revision purposes.
However, I noticed that when an edit is made for a particular student, that subject(s) is duplicated for everyone in the class even if they have their scores already.
Please see image below to get an idea of what I mean.
MY MODEL:
public function addrn($data3) {
$this->db->insert_batch('mtscores_rn', $data3);
return $this->db->affected_rows();
}
MY CONTROLLER:
function assigngradeActionRNMT()
{
//var_dump(count($this->input->post('number')));
for($i=0; $i<count($this->input->post('number')); $i++)
{
$data3[]=array(
'section_id' => $this->input->post('section_id'),
'subject_id' => $this->input->post('subject_id'),
'class_id' => $this->input->post('class_id')[$i],
'student_id' => $this->input->post('student_id')[$i],
'session_id' => $this->input->post('session_id'),
'mt_ca1' => $this->input->post('mt_ca1')[$i],
'mt_ca2' => $this->input->post('mt_ca2')[$i],
'mt_ca3' => $this->input->post('mt_ca3')[$i],
);
}
//var_dump($data3);
$inserted = $this->mtprimary_model->addrn($data3);
if($inserted > 0)
{
$this->session->set_flashdata('msg', '<div class="alert alert-success">Grade Added successfully</div>');
//Echo back success json
redirect('admin/mtprimary/index');
}
}
MY VIEW:
<?php foreach($students as $student){ ?>
<div class="row">
<div class="col-lg-3">
<div class="form-group">
<label>Student Name</label>
<input type="hidden" name="number[]" value="">
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
<input type="hidden" name="session_id" value="<?php echo $student->session_id; ?>">
<input type="hidden" name="student_id[]" value="<?php echo $student->student_id; ?>">
<input type="hidden" name="class_id[]" value="<?php echo $class_id; ?>">
<input type="text" value="<?php echo $CI->GetStudentNameWithID($student->student_id); ?>" class="form-control " readonly>
</div>
</div>
<div class="col-lg-3">
<label>Class Expectation </label>
<textarea name="mt_ca1[]" class="form-control" rows="3" ><?php echo $student->mtscores? $student->mtscores->mt_ca1: 0; ?></textarea>
</div>
<div class="col-lg-3">
<label>Milestone Achieved</label>
<textarea name="mt_ca2[]" class="form-control" rows="3" ><?php echo $student->mtscores? $student->mtscores->mt_ca2: 0; ?></textarea>
</div>
<div class="col-lg-2">
<div class="form-group">
<label>Remark</label>
<input type="text" name="mt_ca3[]" class="form-control" value="<?php echo $student->mtscores? $student->mtscores->mt_ca3: 0; ?>" >
</div>
</div>
</div>
Use this Updated Code in Your Model
public function addrn($data3)
{
$statusIns=$this->checkAlreadyExistOrNor();
if($statusIns==0){
$this->db->insert_batch('mtscores_rn', $data3);
}else{
$this->db->where($data3);
$this->db->update('mtscores_rn', $data3);
}
return $this->db->affected_rows();
}
public function checkAlreadyExistOrNor($data3){
$this->db->select(*);
$this->db->where($data3);
$result=$this->db->get();
$listData=$result->result_array();
if(!empty($listData)){
return 1;
}else{
return 0;
}
}
I was about to update my existing data in sql.
I am updating the data using ajax with validation error
ajax validation works on my account creation and change password
below are my ajax code
$('#form-battery-update').submit(function(e) {
e.preventDefault();
var me = $(this);
// perform ajax
$.ajax({
// url: me.attr('action'),
url: '<?php echo base_url(); ?>msasset/update_battery_form_validation',
type: 'post',
data: me.serialize(),
dataType: 'json',
success: function(response) {
if (response.success == true) {
// if success we would show message
// and also remove the error class
$('#the-message').append('<div class="alert alert-success">' +
'<span class="glyphicon glyphicon-ok"></span>' +
' UPS Battery has been created' +
'</div>');
$('.form-group').removeClass('has-error')
.removeClass('has-success');
$('.text-danger').remove();
// reset the form
me[0].reset();
// close the message after seconds
$('.alert-success').delay(500).show(10, function() {
$(this).delay(3000).hide(10, function() {
$(this).remove();
});
})
}
else {
$.each(response.messages, function(key, value) {
var element = $('#' + key);
element.closest('div.form-group')
.removeClass('has-error')
.addClass(value.length > 0 ? 'has-error' : 'has-success')
.find('.text-danger')
.remove();
element.after(value);
});
}
}
});
});
below are my code from my views folder
<div class="card-body p-0">
<?php echo form_open("msasset/update_battery_form_validation", array("id" => "form-battery-update", "class" => "form-horizontal")) ?>
<div class="row">
<div class="col-lg-5 d-none d-lg-block bg-register-image"></div>
<div class="col-lg-7">
<div class="p-5">
<div class="text-center">
<h1 class="h4 text-gray-900 mb-4"><?php echo $title; ?></h1>
<div id="the-message"></div>
</div>
<?php
if(isset($fetch_single_battery))
{
foreach($fetch_single_battery->result() as $row)
{
?>
<div class="form-group">
<label>Battery SerialNumber</label> </br>
<p class="form-control"> <?php echo $row->SerialNumber; ?></p>
</div>
<div class="form-group">
<label>PO Number</label> </br>
<input type="text" name="PONumber" value="<?php echo $row->PONumber; ?>" class="form-control"/>
</div>
<div class="form-group">
</div>
<div class="form-group">
<label>Ticket</label>
<input type="text" name="ticketid" value="<?php echo $row->TicketNumber; ?>" class="form-control" />
<span class="text-danger"><?php echo form_error("ticketid"); ?></span>
</div>
<div class="form-group">
</div>
<div class="form-group">
<label>Data Port</label>
<select class="form-control" name="select_port">
<option class="form-control" selected><?php echo $row->DataPort; ?></option>
<?php foreach ($GetPortLocation as $Port) { ?>
<option value="<?php echo $Port['DataPort']; ?>"><?php echo $Port['DataPort']; ?></option>
<?php } ?>
</select>
<span class="text-danger"><?php echo form_error("select_port"); ?></span>
<span class="text-danger"></span>
</div>
<div class="form-group">
<label>UPS Asset Tag</label>
<input type="text" name="ups_asset_tag" value="<?php echo $row->UPS_AssetTag; ?>" class="form-control" />
<span class="text-danger"></span>
</div>
<div class="form-group">
<label>Date Installed</label>
<input type="date" name="date_installed" value="<?php echo $row->DateInstalled; ?>" class="form-control" />
<span class="text-danger"></span>
</div>
<div class="form-group">
<label>Status</label>
<select class="form-control" name="select_status">
<option class="form-control" selected><?php echo $row->Status; ?></option>
<?php foreach($get_AssetStatus as $AssetStatus){?>
<option value="<?php echo $AssetStatus['AssetStatus']; ?>"><?php echo $AssetStatus['AssetStatus']; ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<input type="hidden" name="hidden_id" value="<?php echo $row->ID; ?>" />
<input type="submit" name="update" id="update" value="Update" class="btn btn-info" />
<input type="submit" name="insert" id="insert" value="Update" class="btn btn-primary">
</div>
<?php
}
}
?>
</form>
</div>
</div>
</div>
</div>
below codes from my controller
function update_battery_form_validation()
{
$data = array('success' => false, 'messages' => array());
$this->load->library('form_validation');
$this->form_validation->set_rules('PONumber','po number','required');
// $this->form_validation->set_rules('ticketid','ticket id','required');
if($this->form_validation->run() == TRUE)
{
$this->load->model('assets_model');
$data = array(
'PONumber' => $this->input->post('PONumber'),
'TicketNumber' => $this->input->post('ticketid'),
'DataPort' => $this->input->post('select_port'),
'UPS_AssetTag' => $this->input->post('ups_asset_tag'),
'DateInstalled' => $this->input->post('date_installed'),
'Status' => $this->input->post('select_status'),
'PerformedBy' => $this->session->userdata('user_name')
);
if($this->input->post('update'))
{
$this->assets_model->update_battery($data,$this->input->post('hidden_id'));
$this->session->set_flashdata('batteries_updated','New battery has been updated successfully');
redirect('msasset/ups_batteries');
}
}
else
{
// echo validation_errors();
foreach ($_POST as $key => $value)
{
$data['messages'][$key] = form_error($key);
}
}
echo json_encode($data);
}
I was expecting that every time there is an empty fields it should give me an a this fields required messages and also if all the fields fill with data it also does not load the page or save the data
When I click on update, a page is only getting refreshed, values are not updated. I have 4 tables in database, namely -> stud,country_master_academic,master_state, master_city. In a console, values are not showing when I click on update button.
my update.php page
<div class="container" style="width:700px;height:1100px;margin-top:10%;box-shadow:4px 3px 3px 3px grey;margin-left:25%;background-color:#eaf2fa;padding:3%;">
<h4 style="font-weight:bold;"><span class="glyphicon glyphicon-edit"></span>Update Student</h4>
<div class="form-group">
<label for="photo"></label>
<?php
$img = "images/".trim($vrow["photo"]);
echo '<img src='.$img.' id="resultedPhoto" class="image" style="margin-left:75%;margin-top:2%;width:120px;height:120px;border:2px solid #bbbbbb;border-radius:10px;">';
?><br/>
<input type="file" name="upphoto" id="upphoto" style="margin-left:70%;" required />
</div>
<form class="form-horizontal" name="form1" id="form1" method="post" action="<?php $_PHP_SELF?>" enctype="multipart/form-data">
<div class="form-group">
<label for="no"><span class="glyphicon glyphicon-lock"></span><b> Student No: </b></label>
<input type="text" class="form-control" name="upno" id="upno" disabled value="<?php echo $vrow['stud_no'];?>" required />
</div>
<div class="form-group">
<label for="name"><span class="glyphicon glyphicon-user"></span><b> Student Name: </b></label>
<input type="text" class="form-control" name="upname" id="upname" value="<?php echo $vrow['stud_name'];?>" required pattern="[a-zA-Z]{3,}" title="Name should only contain letters and atleast 3 letters"/>
</div>
<div class="form-group">
<label for="no"><span class="glyphicon glyphicon-phone"></span><b> Mobile No: </b></label>
<input type="text" class="form-control" value="<?php echo $vrow['mobile']; ?>" name="upmob_no" required id="upmob_no" pattern="[0-9]{10}" title="Mobile number should be of 10 digits"/>
</div>
<div class="form-group">
<label for="dob"><span class="glyphicon glyphicon-calendar"></span><b> Birth Date: </b></label>
<input type="date" required class="form-control" value="<?php echo $vrow['dob'];?>" name="updob" id="updob" />
</div>
<div class="form-group">
<label for="add"><span class="glyphicon glyphicon-map-marker"></span><b> Address: </b></label>
<textarea rows="4" cols="33" class="form-control" name="upadd" id="upadd" required><?php echo $vrow['address'];?></textarea>
</div>
<div class="form-group">
<label for="gen"><b> Gender: </b></label>
<input type="radio" name="gender" id="genderMale" value="M"<?php echo ($vrow['gender']=='M')?'checked':' ' ?> required="required">Male
<input type="radio" name="gender" id="genderFemale" value="F"<?php echo ($vrow['gender']=='F')?'checked':' ' ?> required="required">Female
</div>
<div class="form-group">
<label for="cntry"><span class="glyphicon glyphicon-map-marker"></span><b> Country: </b></label>
<select required name="upcountry" id="upcountry" class="form-control">
<option value="">Select</option>
<?php
$country="SELECT * from country_master_academic";
$res= $conn->query($country);
if($res->num_rows>0){
while($row=$res->fetch_assoc()){
if($row["country_name"]==$vcountry or $vrow['country'] == $row["country_code"] )
{
echo '<option value='.$row["country_code"].' selected>'.$row["country_name"].'</option>';
}
else
{
echo '<option value='.$row["country_code"].'>'.$row["country_name"].'</option>';
}
}
}
?>
</select>
</div>
<div class="form-group">
<label for="state"><span class="glyphicon glyphicon-map-marker"></span><b> State: </b></label>
<select required name="upstate" id="upstate" class="form-control">
<option value="">Select</option>
<?php
$state="SELECT * from master_state";
$res= $conn->query($state);
if($res->num_rows>0){
while($row=$res->fetch_assoc()){
if($row["state_name"]==$vstate or $vrow['state'] == $row["state_code"] )
{
echo '<option value='.$row["state_code"].' selected>'.$row["state_name"].'</option>';
}
else
{
echo '<option value='.$row["state_code"].'>'.$row["state_name"].'</option>';
}
}
}
?>
</select>
</div>
<div class="form-group">
<label for="city"><span class="glyphicon glyphicon-map-marker"></span><b> City: </b></label>
<select required name="upcity" id="upcity" class="form-control">
<option value="">Select</option>
<?php
$city="SELECT * from master_city";
$res= $conn->query($city);
if($res->num_rows>0){
while($row=$res->fetch_assoc()){
if($row["city_name"]==$vcity or $vrow['city'] == $row["city_code"] )
{
echo '<option value='.$row["city_code"].' selected>'.$row["city_name"].'</option>';
}
else
{
echo '<option value='.$row["city_code"].'>'.$row["city_name"].'</option>';
}
}
}
?>
</select>
</div>
<br/>
<div class="form-group">
<button type="submit" name="update" id="update" style="font-weight:bold;" class="btn btn-primary">Update</button>
</div>
</form>
</div>
upresult.php page
<?php
include("connection.php");
$no=trim($_POST['upno']);
$name=trim($_POST['upname']);
$mob=trim($_POST['upmob_no']);
$dob=trim($_POST['updob']);
$add=trim($_POST['upadd']);
$photo=trim($_FILES['upphoto']['name']);
$gen=trim($_POST['gender']);
$cn=trim($_POST['upcountry']);
$st=trim($_POST['upstate']);
$ct=trim($_POST['upcity']);
$qry="update stud set stud_name='".$name."',mobile='".$mob."',dob='".$dob."',address='".$add."',gender='".$gen."',country='".$cn."',state='".$st."',city='".$ct."' where stud_no='".$no."'";
$data=mysqli_query($conn,$qry);
if($data)
{
echo '<script language="javascript">';
echo 'alert("Updated Successfully")';
echo '</script>';
}
else {
echo '<script language="javascript">';
echo 'alert("Cannot update record")';
echo '</script>';
}
?>
jquery
$(document).ready(function(){
$("#form1").submit(function(event){
event.preventDefault();
var formData = new FormData(this);
$.ajax({
url:"upresult.php",
type:"POST",
data:{formData:formData},
async:true,
success:function(data) {
alert(data);
},
cache:false,
contentType:false,
processData:false
});
});
});
Thank you in advance.
Don't use the same name
data:{stud_no:stud_no}, //here change the name of vbl or value
data:{
formData:formData, //here change the name of vbl or value
stud_no:stud_no, //here change the name of vbl or value
}
I've been working to make some CRUD I get nothing wrong.
But when I update data I got nothing affected in database and here my code
Table : Song
Column :
id_song,
id_album,
song,
author,
composer
Code for my Model is below:
function Tampil_song_admin(){
return $this->db->get('songs');
}
function Input_song($data,$table){
$this->db->insert($table,$data);
}
function edit_song($where,$table){
return $this->db->get_where($table,$where);
}
function update_song($where,$data,$table){
$this->db->where($where);
$this->db->update($table,$data);
}
function delete_song($where,$table){
$this->db->where($where);
$this->db->delete($table);
}
View:
<?php foreach($songs as $data){ ?>
<form action="<?php echo base_url('/index.php/Admin_song/update_song'); ?>" method="post">
<h4 class="header-title m-t-0 m-b-30"></h4>
<div class="form-group">
<label for="userName">id_songs </label>
<input type="text" name="id_song" parsley-trigger="change" required
value="<?php echo $data->id_song; ?>"
class="form-control" disabled="" id="userName">
</div>
<div class="form-group">
<label for="userName">id_album</label>
<input type="text" name="id_album" parsley-trigger="change" required
value="<?php echo $data->id_album; ?>" class="form-control" id="userName">
</div>
<div class="form-group">
<label for="userName">Songs</label>
<input type="text" name="song" parsley-trigger="change" required
value="<?php echo $data->song; ?>" class="form-control" id="userName">
</div>
<div class="form-group">
<label for="userName">Author</label>
<input type="text" name="author" parsley-trigger="change" required
value="<?php echo $data->author; ?>" class="form-control" id="userName">
</div>
<div class="form-group">
<label for="userName">Composer</label>
<input type="text" name="composer" parsley-trigger="change" required
value="<?php echo $data->composer; ?>" class="form-control" id="userName">
</div>
<button type="submit" class="btn btn-success waves-effect w-md waves-light m-b-5">Update</button>
<button type="button" class="btn btn-danger waves-effect w-md waves-light m-b-5">Reset</button>
</form>
<?php } ?>
And this is for Controller:
function index(){
$data['songs'] = $this->m_admin_data->Tampil_song_admin()->result();
$this->load->view('admin/v_admin_song',$data);
}
//Tambah Data
function add_song(){
$this->load->view('admin/v_admin_song_add');
}
function proses_tambah(){
$id_album = $this->input->post('id_album');
$song = $this->input->post('song');
$author = $this->input->post('author');
$composer = $this->input->post('composer');
$data = array(
'id_album' => $id_album,
'song' => $song,
'author' => $author,
'composer' => $composer
);
$this->m_admin_data->Input_song($data,'songs');
redirect('Admin_song/index');
}
//Update/Edit Data
function edit_song($id){
$where = array('id_song' => $id);
$data['songs'] = $this->m_admin_data->edit_song($where,'songs')->result();
$this->load->view('admin/v_admin_song_edit',$data);
}
function update_song(){
$id = $this->input->post('id_song');
$id_album = $this->input->post('id_album');
$song = $this->input->post('song');
$author = $this->input->post('author');
$composer = $this->input->post('composer');
$data = array(
'id_album' => $id_album,
'song' => $song,
'author' => $author,
'composer' => $composer
);
$where = array(
'id_song' => $id
);
$this->m_admin_data->update_song($where,$data,'songs');
redirect('Admin_song/index');
}
//Hapus Data
function delete_song($id){
$where = array('id_song' => $id);
$this->m_admin_data->delete_song($where,'songs');
redirect('Admin_song/index');
}
See I got nothing wrong but when I edit and try to update some data its not affected.
Hope this will help you :
You have disabled you id_song input type in your form just remove disabled attr from it
Because of this u r unable to get id_song post value in your update_song method in turn not getting in your where clause so
id_song input Should be like this :
<div class="form-group">
<label for="userName">id_songs </label>
<input type="text"
name="id_song"
value="<?php echo $data->id_song; ?>"
class="form-control" id="userName">
</div>
Or just make it hidden if you don't want to show it like this :
<input type="hidden"
name="id_song"
parsley-trigger="change" required
value="<?php echo $data->id_song; ?>"
class="form-control" id="userName">
I've been building a site recently for a friend and I've gotten stuck on this one form. A button links to url in which this form is on and then once you fill out all the information and click submit, instead of returning you back to home.php it just removes the form from view and all you see is a blank new.php and it doesn't submit the information.
<?php
function renderForm($user, $rank, $position, $error)
{
?>
<?php
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>
<center>
<form action="" method="post">
<div class="form-group">
<label for="username">Username*</label>
<input id="username" class="form-control" type="text" name="user" placeholder="Username" value="<?php echo $user; ?>" />
</div>
<div class="form-group">
<label for="rank">Rank</label>
<select class="form-control" name="rank">
<option value="1">Pending Rank</option>
<option value="2">PVT</option>
</select>
</div>
<div class="form-group">
<label for="position">Position</label>
<input id="position" class="form-control" type="text" name="position" placeholder="MOG/GG" value="<?php echo $position; ?>" />
</div>
<div class="form-group">
<label for="Date">Date*</label>
<input id="Date" class="form-control" type="text" name="date" placeholder="<?php echo date('d M y'); ?>" value="<?php echo $date; ?>" />
</div>
<div class="form-group">
<label for="Tag">Tag*</label>
<input id="Tag" class="form-control" type="text" name="tag" placeholder="[]" value="<?php echo $tag; ?>" />
</div>
<div class="form-group">
<label for="adt">ADT</label>
<input id="adt" class="form-control" type="text" name="adt" placeholder="{TEST}" value="<?php echo $adt; ?>" />
</div>
<div class="form-group">
<label for="exp">EXP</label>
<input id="exp" class="form-control" type="text" name="exp" placeholder="420" value="<?php echo $exp; ?>" />
</div>
<div class="form-group">
<label for="reg">Regiment</label>
<input id="reg" class="form-control" type="text" name="reg" placeholder="[P]" value="<?php echo $reg; ?>" />
</div>
<div class="form-group">
<label for="Notes">Notes</label>
<input id="Notes" class="form-control" type="text" name="notes" placeholder="Notes" value="<?php echo $notes; ?>" />
</div>
<button type="submit" name="submit" class="btn btn-default" value="Submit">Submit</button>
</form>
<script>
$('.modal').on('hidden.bs.modal', function(){
$(this).find('form')[0].reset();
});
</script>
<?php
}
include('config/db.php');
if (isset($_POST['submit']))
{
$user = mysql_real_escape_string(htmlspecialchars($_POST['user']));
$rank = mysql_real_escape_string(htmlspecialchars($_POST['rank']));
$position = mysql_real_escape_string(htmlspecialchars($_POST['position']));
$date = mysql_real_escape_string(htmlspecialchars($_POST['date']));
$tag = mysql_real_escape_string(htmlspecialchars($_POST['tag']));
$adt = mysql_real_escape_string(htmlspecialchars($_POST['adt']));
$exp = mysql_real_escape_string(htmlspecialchars($_POST['exp']));
$reg = mysql_real_escape_string(htmlspecialchars($_POST['reg']));
$notes = mysql_real_escape_string(htmlspecialchars($_POST['notes']));
$datej = mysql_real_escape_string(htmlspecialchars($_POST['date']));
if ($user == '' || $rank == '' || $date == '' || $tag == '')
{
$error = '<center>ERROR: Please fill in all required fields!</center>';
#renderForm($user, $rank, $position, $error);
}
else
{
mysql_query("INSERT per SET user='$user', rank='$rank', position='$position', date='$date', tag='$tag', adt='$adt', exp='$exp', reg='$reg', notes='$notes', datej='$datej'", $db1)
or die(mysql_error());
include('logsadd.php');
write_mysql_log('has added member <font color="black"><b>'. $user .'</b></font>.', $db);
header("Location: home.php");
}
}
else
header("home.php");
{
#renderForm('','','');
}?>
Your else looks like this
else
header("home.php");
{
#renderForm('','','');
it should be
else
{
// header should be inside the else part
header("Location:home.php");
#renderForm('','','');