CodeIgniter Form validation fails and doesn't show a message - php

I have a dynamic form that is generated depending on how many people are selected from another page. When I submit this form however, the form validation fails without giving me an error. Could someone take a look and see why it's failing? I have tried debugging it but I can't see it. Maybe my method is wrong? This form used to work as well. It started to not work after I added the form processing for the children. Hopefully someone can help. Thank you so much.
Controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Details extends TX_Controller {
public function __construct(){
parent::__construct();
ini_set('memory_limit', '64M');
$this->load->model('TransactionsModel');
$this->load->model('ProductsModel');
}
public function index(){
$data['productdetail'] = $this->ProductsModel->getProduct($this->session->userdata('productid'));
// var_dump($data['productdetail']);
$data['adults'] = $this->session->userdata('adults');
$data['children'] = $this->session->userdata('children');
$this->load->view('public/publicMenu/navigationLink');
$this->load->view('public/publicDetails/details',$data);
$this->load->view('public/publicMenu/navigationJquery');
}
public function next(){
$adultlength = $this->input->post('adults');
$childrenlength = $this->input->post('children');
$this->form_validation->set_error_delimiters('<p class="error">', '</p>');
for ($i=0; $i < $adultlength; $i++) {
$this->form_validation->set_rules('inputfirstname['.$i.']', 'Firstname', 'trim|required');
$this->form_validation->set_rules('inputlastname['.$i.']', 'Lastname', 'trim|required');
$this->form_validation->set_rules('inputdateofbirth['.$i.']', 'Date of Birth', 'trim|required');
$this->form_validation->set_rules('inputicnumber['.$i.']', 'IC Number', 'trim|required');
$this->form_validation->set_rules('inputmobilenumber['.$i.']', 'Mobile Number', 'trim|required');
$this->form_validation->set_rules('inputemail['.$i.']', 'Email', 'trim|required');
$this->form_validation->set_rules('inputconfirmemail['.$i.']', 'Confirm Email', 'trim|required');
$inputfirstname[] = $this->input->post('inputfirstname['.$i.']');
$inputlastname[] = $this->input->post('inputlastname['.$i.']');
$inputdateofbirth[] = $this->input->post('inputdateofbirth['.$i.']');
$inputicnumber[] = $this->input->post('inputicnumber['.$i.']');
$inputmobilenumber[] = $this->input->post('inputmobilenumber['.$i.']');
$inputemail[] = $this->input->post('inputemail['.$i.']');
$inputpostcode[] = $this->input->post('inputpostcode['.$i.']');
}
for($j=0;$j<$childrenlength;$j++){
$inputchildfirstname[] = $this->input->post('inputchildfirstname['.$j.']');
$inputchildlastname[] = $this->input->post('inputchildlastname['.$j.']');
$inputchilddateofbirth[] = $this->input->post('inputchilddateofbirth['.$j.']');
}
if($this->form_validation->run()==false){
$data['productdetail'] = $this->ProductsModel->getProduct($this->session->userdata('productid'));
$data['adults'] = $this->session->userdata('adults');
$data['children'] = $this->session->userdata('children');
$this->load->view('public/publicMenu/navigationLink');
$this->load->view('public/publicDetails/details',$data);
$this->load->view('public/publicMenu/navigationJquery');
}else{
for ($i=0; $i < $adultlength; $i++) {
$passengerdetails[] = array(
'firstname'=>$inputfirstname[$i],
'lastname'=>$inputlastname[$i],
'dateofbirth'=>$inputdateofbirth[$i],
'icnumber'=>$inputicnumber[$i],
'mobilenumber'=>$inputmobilenumber[$i],
'email'=>$inputemail[$i],
'postcode'=>$inputpostcode[$i],
'usertype'=>'adult'
);
}
if($childrenlength>0){
for($j=0;$j<$childrenlength;$j++){
$childpassengerdetails[] = array(
'firstname'=>$inputchildfirstname[$j],
'lastname'=>$inputchildlastname[$j],
'dateofbirth'=>$inputchilddateofbirth[$j],
'icnumber'=>'',
'mobilenumber'=>'',
'email'=>'',
'postcode'=>'',
'usertype'=>'child'
);
}
$this->session->set_userdata('childpassengerdetails',json_encode($childpassengerdetails));
}
$this->session->set_userdata('passengerdetails',json_encode($passengerdetails));
redirect('/Public/Payment');
}
}
}
View
<section id="about" class="container content-section text-center">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<h2><?php echo $productdetail->name;?></h2>
<h2>Enter Passenger Details</h2>
<?php echo form_open_multipart('Public/Details/next','class="inputform"');?>
<h3>Adults</h3>
<?php for($i=0;$i<$adults;$i++){?>
<input type="hidden" class="form-control" name="adult" value="<?php echo $adults;?>">
<label for="inputfirstname">Firstname</label>
<input type="text" class="form-control" name="inputfirstname[]" placeholder="Firstname" value="<?php echo set_value('inputfirstname['.$i.'],""');?>">
<div class="errormessage"><?php echo form_error('inputfirstname['.$i.']'); ?></div>
<label for="inputfirstname">Lastname</label>
<input type="text" class="form-control" name="inputlastname[]" placeholder="Lastname" value="<?php echo set_value('inputlastname[$i]');?>">
<div class="errormessage"><?php echo form_error('inputlastname['.$i.']'); ?></div>
<label for="inputdateofbirth">Date of Birth</label>
<input type="date" class="form-control" name="inputdateofbirth[]" value="<?php echo set_value('inputdateofbirth[$i]');?>">
<div class="errormessage"><?php echo form_error('inputdateofbirth['.$i.']'); ?></div>
<label for="inputicnumber">IC Number</label>
<input type="text" class="form-control" name="inputicnumber[]" placeholder="IC Number" value="<?php echo set_value('inputicnumber[$i]');?>">
<div class="errormessage"><?php echo form_error('inputicnumber['.$i.']'); ?></div>
<label for="inputmobilenumber">Mobile Number</label>
<input type="text" class="form-control" name="inputmobilenumber[]" placeholder="Mobile Number" value="<?php echo set_value('inputmobilenumber[$i]');?>">
<div class="errormessage"><?php echo form_error('inputmobilenumber['.$i.']'); ?></div>
<label for="inputemail">Email</label>
<input type="text" class="form-control" name="inputemail[]" placeholder="Email" value="<?php echo set_value('inputemail[$i]');?>">
<div class="errormessage"><?php echo form_error('inputemail['.$i.']'); ?></div>
<label for="inputconfirmemail">Confirm Email</label>
<input type="text" class="form-control" name="inputconfirmemail[]" placeholder="Confirm Email" value="<?php echo set_value('inputconfirmemail[$i]');?>">
<div class="errormessage"><?php echo form_error('inputconfirmemail['.$i.']'); ?></div>
<label for="inputaddress1">Address</label>
<input type="text" class="form-control" name="inputaddress1[]" placeholder="Address 1" value="<?php echo set_value('inputaddress1[$i]');?>">
<input type="text" class="form-control" name="inputaddress2[]" placeholder="Address 2" value="<?php echo set_value('inputaddress2[$i]');?>">
<input type="text" class="form-control" name="inputaddress3[]" placeholder="Address 3" value="<?php echo set_value('inputaddress3[$i]');?>">
<input type="text" class="form-control" name="inputaddress4[]" placeholder="Address 4" value="<?php echo set_value('inputaddress4[$i]');?>">
<input type="text" class="form-control" name="inputaddress5[]" placeholder="Address 5" value="<?php echo set_value('inputaddress5[$i]');?>">
<label for="inputpostcode">Postcode</label>
<input type="text" class="form-control" name="inputpostcode[]" placeholder="Postcode1" value="<?php echo set_value('inputpostcode[$i]');?>">
<div class="errormessage"><?php echo form_error('inputpostcode['.$i.']'); ?></div>
<?php } ?>
<?php if($children>0){ ?>
<h3>Children</h3>
<?php for($j=0;$j<$children;$j++){ ?>
<input type="hidden" class="form-control" name="children" value="<?php echo $children;?>">
<label for="inputchildfirstname">Firstname</label>
<input type="text" class="form-control" name="inputchildfirstname[]" value="<?php echo set_value('inputchildfirstname[$j]');?>" placeholder="Firstname">
<label for="inputchildlastname">Lastname</label>
<input type="text" class="form-control" name="inputchildlastname[]" value="<?php echo set_value('inputchildlastname[$j]');?>" placeholder="Lastname">
<label for="inputchilddateofbirth">Date of Birth</label>
<input type="date" class="form-control" name="inputchilddateofbirth[]" value="<?php echo set_value('inputchilddateofbirth[$j]');?>">
<?php }} ?>
<p><button type="submit" class="btn btn-primary">Next</button></p>
<p>Cancel</p>
<?php echo form_close(); ?>
<p><?php echo $this->session->flashdata('Form'); ?></p>
</div>
</div>
</section>

Related

How to retain the form inputs when submit button is clicked?

So I got a form that gets the student basic information for temporary admission, so I have a function that when register/submit button is clicked it checks if the Or number is already exist in database when it does it displays error message and the inputted data stays in their own fields.
the function works but when a user inputted a name for example "james joseph" and or number exist in database it will retain the name "james" only.
is there a way that it retains both?
Here's my code for the form
<form class="form-group" method="post" action="index.php">
<div class="row"><!--Top row-->
<div class="col-lg-5"><p><h3>Register an Enrollee</h3></p></div>
<div class="col-lg-3"></div>
<div class="col-lg-4">
</div>
</div>
<br>
<br>
<div class="row">
<div class="col-lg-4">
<label>Academic Year </label>
<?php
if (isset($_GET['academic'])) {
$academic=$_GET['academic'];
echo '<input type="text" name="academic" class="form-control" required value='.$academic.'>';
# code...
}
else
{
echo '<input type="text" name="academic" class="form-control" required>';
}
?>
</div>
<div class="col-lg-4">
<label for="year_level">Year Level</label>
<?php
if (isset($_GET['year'])) {
$year=$_GET['year'];
echo '<input type="text" name="year" class="form-control" required value='.$year.'>';
# code...
}
else
{
echo '<input type="text" name="year" class="form-control" required>';
}
?>
</div>
<div class="col-lg-4">
<label>OR Number</label>
<?php
if (isset($_GET['or'])) {
$or=$_GET['or'];
echo '<input type="text" name="or" class="form-control" required value='.$or.'>';
# code...
}
else
{
echo '<input type="text" name="or" class="form-control" required>';
}
?>
</div>
</div>
<br>
<div class="row">
<div class="col-lg-4">
<label>First Name</label>
<?php
if (isset($_GET['firstname'])) {
$firstname=$_GET['firstname'];
echo '<input type="text" name="firstname" class="form-control" required value='.$firstname.'>';
# code...
}
else
{
echo '<input type="firstname" name="firstname" class="form-control" required>';
}
?>
</div>
<div class="col-lg-4">
<label>Last Name</label>
<?php
if (isset($_GET['lastname'])) {
$lastname=$_GET['lastname'];
echo '<input type="text" name="lastname" class="form-control" required value='.$lastname.'>';
# code...
}
else
{
echo '<input type="text" name="lastname" class="form-control" required>';
}
?>
</div>
<div class="col-lg-4">
<label>Middle Initial</label>
<?php
if (isset($_GET['middle'])) {
$middle=$_GET['middle'];
echo '<input type="text" name="middle" class="form-control" required value='.$middle.'>';
# code...
}
else
{
echo '<input type="text" name="middle" class="form-control" required>';
}
?>
</div>
</div><!--End of Second row-->
<br>
<button class="btn btn-primary btn-block" type="submit" name="register">Register</button>
</form>
Here is the php code that checks and gets the inputted data from the form
if (isset($_POST['register'])) {
# code...
$year_level=$_POST['year'];
$academic_year=$_POST['academic'];
$or_number=$_POST['or'];
$stud_fname=$_POST['firstname'];
$stud_lname=$_POST['lastname'];
$stud_mi=$_POST['middle'];
$or_check_query="SELECT * FROM tbl_user WHERE or_number=$or_number";
$result=mysqli_query($conn,$or_check_query);
$or=mysqli_fetch_assoc($result);
if($or['or_number']===$or_number) {
header("Location: index.php?signup=failed&academic=$academic_year&year=$year_level&or=$or_number&firstname=$stud_fname&lastname=$stud_lname&middle=$stud_mi");
# code...
}
else {
$sql= "INSERT INTO tbl_user(or_number,academic,year,firstname,lastname,middle)
VALUES ('$or_number','$academic_year','$year_level','$stud_fname','$stud_lname','$stud_mi')";
mysqli_query($conn,$sql);
header("Location: index.php?signup=success");
}
}

make text input hide and show with radio button

I am trying to make a radio button with 2 options i.e. option A and Option B.
I have 2 text input ( A and B ) and some other text input that always has to be there.
Option A of the radio button has to make disappear text input (A) and show another text input (B). Option B should make this the opposite. ( disappear text input (B) and show another text input (A) )
I don't know how to make that 2 text inputs.
will appreciate some help.
<form class="user" id="RegisterForm" action="" method="post">
<? print("USER ROLE : ") ?>
<input type="radio" name="user_role" <?php if (isset($user_role) && $user_role=="A") echo "checked";?> value="A">A
<input type="radio" name="user_role" <?php if (isset($user_role) && $user_role=="B") echo "checked";?> value="B">B
//REST OF the code defines some text inputs that are always should show.
<?php if ($fullname_req != "-1") { ?>
<div class="form-group">
<input type="text" class="form-control form-control-user" id="displayname" name="fullname" placeholder="<?php _e('Display name', 'user-panel-pro') ?>">
</div>
<?php } ?>
<?php if ($firstname_req != "-1") { ?>
<div class="form-group row">
<?php if ($firstname_req != "-1" or $lastname_req != "-1") { ?>
<div class="col-sm-6 mb-3 mb-sm-0">
<input type="text" class="form-control form-control-user" id="First-Name" name="firstname" placeholder="<?php _e('first name', 'user-panel-pro') ?>">
</div>
<?php } ?>
<?php if ($lastname_req != "-1") { ?>
<div class="col-sm-6">
<input type="text" class="form-control form-control-user" id="Last-Name" name="lastname" placeholder="<?php _e('last name', 'user-panel-pro') ?>">
</div>
<?php } ?>
</div>
<?php } ?>
<?php if ($username_req != "-1") { ?>
<div class="form-group">
<input type="text" class="form-control form-control-user" id="User-Name" name="username" placeholder="<?php _e('Username', 'user-panel-pro') ?>">
</div>
<?php } ?>
<?php if ($email_req != "-1") { ?>
<div class="form-group">
<input type="email" class="form-control form-control-user" id="Email" name="email" placeholder="<?php _e('Email', 'user-panel-pro') ?>">
</div>
<?php } ?>
I am not able to understand your code, so I am just giving a small demo
<div class="radioBtns">
<label for='rbtnLoginTypeMobile'><input checked type="radio" id="rbtnLoginTypeMobile" name="rbtnLoginType" value='1' onclick="showLogin(1)"/><span>Mobile</span></label>
<label for='rbtnLoginTypeEmail'><input type="radio" id="rbtnLoginTypeEmail" name="rbtnLoginType" value='0' onclick="showLogin(0)" /><span>Email</span></label>
</div>
<div class="mobilelogin">Your Mobile Div</div>
<div class="emaillogin">Your Email Div</div>
<script type="text/javascript">
function showLogin(val)
{
if(val==1)
{
$('.emaillogin').css('display','none');
$('.mobilelogin').css('display','');
}
else
{
$('.mobilelogin').css('display','none');
$('.emaillogin').css('display','');
}
}
</script>

Adding outputted table row to another table using codeigniter

Outputted a row from a table ,am now trying to add some of the contents to another table using a form which is inside the outputted row but its not inserted to the database. am not getting an error.
Here is my view
<?php
foreach ($h->result() as $row)
{?>
<div class="row invoice-info">
<div class="col-sm-1 invoice-col">
</div>
<div class="col-sm-3 invoice-col">
<img src="<?php echo base_url()?>/res/images/goods/1.png">
</div>
<div class="col-sm-4 invoice-col">
<address>
Description: <?php echo $row->description;?><br>
Location Address: <?php echo $row->l_area;?><br>
Destination Address: <?php echo $row->d_area;?><br>
Date: <?php echo $row->dom;?><br>
Time: <?php echo $row->tom;?>
</address>
</div>
<div class="col-sm-2 invoice-col">
<address>
</address>
</div><!-- /.col -->
<div class="col-sm-2 invoice-col">
<form action="<?php echo site_url('truckeraccount_ctrl/bid'); ?>" method="post">
<input type="hidden" class="form-control" name="truckerid" value="<?php
$truckerid = $this->session->userdata('truckerid');
echo $truckerid; ?>" required>
<input type="hidden" class="form-control" name="luggage_id" value="<?php echo $row->luggage_id;?>" placeholder="Bid">
<input type="text" class="form-control" name="bid_amount" placeholder="Bid">
<button type="submit" class="btn bg-orange btn-flat margin">Place Bid</button>
</div>
</div>
My model
function bid($data){
$query=$this->db->update('bids',$data);
return $query;
}
My controller
public function bid(){
$this->load->database();
$this->load->model('Truckeraccount_model');
$data['a']=$this->Truckeraccount_model->accepted_bid();
$data['b']=$this->Truckeraccount_model->picked_loads();
$data['h']=$this->Truckeraccount_model->loads();
$data['g']=$this->Truckeraccount_model->notification();
$data['i']=$this->Truckeraccount_model->return_loads();
$data['accepted_return_loads']=$this->Truckeraccount_model->accepted_return_loads();
$data['bid_amount']=$this->Truckeraccount_model->bid_amount(); $this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
$this->form_validation->set_rules('bid_amount', 'bid_amount', 'required|min_length[1]|max_length[50]');
if ($this->form_validation->run() == FALSE) {
$this->load->view('header');
$this->load->view('truckeraccount_view',$data);
$this->load->view('footer');
} else {
$data = array(
'truckerid' => $this->input->post('truckerid'),
'luggage_id' => $this->input->post('luggage_id'),
'bid_amount' => $this->input->post('bid_amount'),
);
$this->Truckeraccount_model->bid($data);
$data['message'] = '';
redirect('truckeraccount_ctrl/');
}
}
<form action="<?php echo site_url('truckeraccount_ctrl/bid'); ?>" method="post">
<input type="hidden" class="form-control" name="truckerid" value="<?php
$truckerid = $this->session->userdata('truckerid');
echo $truckerid; ?>" required>
<input type="hidden" class="form-control" name="luggage_id" value="<?php echo $row->luggage_id;?>" placeholder="Bid">
<input type="text" class="form-control" name="bid_amount" placeholder="Bid">
<button type="submit" class="btn bg-orange btn-flat margin">Place Bid</button>
</form>

Unable to access an error message - Callback validation in CodeIgniter

I have simple code thats not working. I made validation for checkbox and I get error:
Unable to access an error message corresponding to your field name accept_terms_checkbox.(accept_terms)
This is my code:
Controller:
public function formularz2()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$data['szkolenia'] = $this->Szkolenie_m->pobierz();
//VALIDATION!!
$this->form_validation->set_rules('imie', 'Imię', 'required');
$this->form_validation->set_message('required', 'Błąd: wypełnij powyższe pole');
$this->form_validation->set_rules('accept_terms_checkbox', 'checkbox', 'callback_accept_terms');
//CALLBACK FUNCTION!!
function accept_terms()
{
if ($this->input->post('accept_terms_checkbox'))
{
return TRUE;
}
else
{
$error = 'Please read and accept our terms and conditions.';
$this->form_validation->set_message('accept_terms', $error);
return FALSE;
}
}
//Po przesłaniu danych
if (!empty($_POST))
{
$konsultant = $this->uri->segment(3);
$dane = array(
'email1' => $this->input->post('email'),
'imie' => $this->input->post('imie'),
'nazwisko' => $this->input->post('nazwisko'),
'nazwa_firmy' => $this->input->post('firma'),
'konsultant_id' => $konsultant,
);
//Trzeba jeszcze tutaj ogarnąć wrzucanie pivotów zaznaczonych checkboxów
$boxes = $_POST['formChecks'];
$N = count($boxes);
$ostatni_id = $this->Osoby_m->ostatni_id();
for($i=0; $i < $N; $i++)
{
$this->Osoby_m->nowy_wpis_formularz($boxes[$i]);
}
//Pobrać id dodanej osoby = policzyć ile osób w bazie +1
$this->Osoby_m->nowa_osoba($dane);
}
if ($this->form_validation->run() == FALSE)
{
$this->load->view('formularz', $data);
}
else
{
$this->load->view('wyslano_formularz');
}
}
My View:
<?php echo form_open(); ?>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email:</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="Email" value="<?php echo set_value('email'); ?>">
<p class="help-block"><?php echo form_error('email'); ?></p>
</div>
</div>
<div class="form-group">
<label for="imie" class="col-sm-2 control-label">Imię:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="imie" name="imie" placeholder="Imię" value="<?php echo set_value('imie'); ?>">
<p class="help-block"><?php echo form_error('imie'); ?></p>
</div>
</div>
<div class="form-group">
<label for="nazwisko" class="col-sm-2 control-label">Nazwisko: </label>
<div class="col-sm-10">
<input type="text" class="form-control" id="nazwisko" name="nazwisko" placeholder="Nazwisko" value="<?php echo set_value('nazwisko'); ?>">
<p class="help-block"><?php echo form_error('nazwisko'); ?></p>
</div>
</div>
<div class="form-group">
<label for="firma" class="col-sm-2 control-label">Firma:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="firma" name="firma" placeholder="Firma" value="<?php echo set_value('firma'); ?>">
<p class="help-block"><?php echo form_error('firma'); ?></p>
</div>
</div>
<div class="col-sm-12" style="margin-bottom: 30px; margin-top: 30px;"> <h3>Wybierz interesujące Cię szkolenia</h3></div>
<div class="form-group">
<label class="col-sm-2 control-label">Szkolenia:</label>
<div class="col-sm-10">
<?php foreach ($szkolenia as $szkolenie): ?>
<div class="checkbox">
<label><input id="szkolenie<?php echo $szkolenie->id; ?>" type="checkbox" name="formChecks[]" value="<?php echo $szkolenie->id; ?>"> <?php echo $szkolenie->nazwa_szkolenia; ?></label>
<br>
</div>
<?php endforeach; ?>
</div>
</div>
//CALLBACK CHECKBOX
<div class="form-group">
<div class="col-sm-12" style="margin-top: 50px;">
<input type="checkbox" name="accept_terms_checkbox" value="1"/> Zgadzam się na otrzymywanie maili od firmy Gamma<br>
<p><?php echo form_error('accept_terms_checkbox') ?></p>
</div>
</div>
<button type="submit" class="btn btn-lg btn-success" style="margin-top: 50px;">Odbierz Voucher</button>
<?php echo form_close(); ?>
In order to use your own callback method with codeigniter's validation class, you must declare the method. IN your case ( add this to your controller or a helper etc...):
public function accept_terms($user_input){
if($user_input != ""){
return True;
}else{
$this->form_validation->set_message('accept_terms_checkbo', 'The %s field can not be empty"');
return False;
}
I fixed this error by simple validation without callback function. I figure out that I don't need callback function for Terms of Services checkbox.
$this->form_validation->set_rules('accept_terms_checkbox', 'Checkbox', 'required');
$this->form_validation->set_message('required', 'You need to accept Terms of Services');

Form won't submit info to database

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('','','');

Categories