Why are session Ids in my table changing to 0? - php

I have a form for submitting students' scores which is supposed to capture the session id (session ids are used to to show the session that a school is currently on e.g 2018/2019 session, 2019/2020 session...)
session table
In the scores table in the database, the session id is automatically captured and inserted. Currently, the session id is 14.
session id
However, for reasons unknown 0s are inserted instead of 14. This is causing so many issues
In the add scores form, scores values are only repopulated if the session id is 14. Now, since it shows 0, the value boxes remain 0
Also I believe it causes duplicate issues. During edits in the form, all scores of students are duplicated.
Controller
function assigngradeAction()
{
for($i=0; $i<count($this->input->post('number')); $i++)
{
$data[]=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'),
'ca1' => $this->input->post('ca1')[$i],
'ca2' => $this->input->post('ca2')[$i],
'ca3' => $this->input->post('ca3')[$i],
'ca4' => $this->input->post('ca4')[$i],
'project' => $this->input->post('project')[$i],
'affective' => $this->input->post('affective')[$i],
'psychomotor' => $this->input->post('psychomotor')[$i],
'exam'=> $this->input->post('exam')[$i],
'tot_score'=> $this->input->post('ca1')[$i] + $this->input->post('ca2')[$i] + $this->input->post('ca3')[$i] + $this->input->post('ca4')[$i] + $this->input->post('project')[$i] + $this->input->post('affective')[$i] + $this->input->post('psychomotor')[$i] + $this->input->post('exam')[$i],
);
}
$inserted = $this->primary_model->add1($data);
if($inserted > 0)
{
$this->session->set_flashdata('msg', '<div class="alert alert-success">Grade Added successfully</div>');
//Echo back success json
redirect('admin/primary/index');
}
}
model
public function add1($data)
{
// for each record insert
foreach($data as $studentScore){
// get score
$subjectId = $studentScore['subject_id'];
$classId = $studentScore['class_id'];
$sessionId = $studentScore['session_id'];
$sectionId = $studentScore['section_id'];
$studentId = $studentScore['student_id'];
$score = $this->get_student_score($subjectId,$sessionId,$sectionId,$classId,$studentId);
$studentScore['modified_at'] = date("Y-m-d H:i:s");
if(empty($score->id)){
$this->db->insert('scores_primary', $studentScore);
}else{
$this->db->where('id', $score->id);
$this->db->update('scores_primary', $studentScore);
}
// var_dump($studentScore, "\n >>>>>>>>", $score);
}
// $this->db->insert_batch('scores_primary', $data);
// var_dump($this->db->error(), $_SERVER['SERVER_ADDR'] );
// $str = $this->db->last_query();
// echo "<pre>";
// print_r($str);
return true;
}
view
<?php }elseif($class_id >= 15 && $class_id <= 17){ ?>
<form action="<?php echo site_url('admin/primary/assigngradeAction') ?>" method="POST" id="formSubjectTeacher">
<?php echo $this->customlib->getCSRF(); ?>
<div class="row">
<div class="col-lg-3">
<input type="hidden" name="class" value="<?php echo $class_id; ?>">
<input type="hidden" name="subject_id" value="<?php echo $subject_id; ?>">
</div>
<div class="col-lg-4">
<h4><strong><?php echo $session_name; ?></strong></h4>
</div>
</div>
<br>
<hr>
<?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-1">
<label>ca1 </label>
<input type="hidden" name="session_id" value="<?php echo $sessionID; ?>">
<input type="number" name="ca1[]" min="0" max="10" class="form-control input-sm rounded-0" value="<?php echo $student->scores? $student->scores->ca1: 0; ?>">
</div>
<div class="col-lg-1" id="t2">
<label>ca2</label>
<input type="number" name="ca2[]" min="0" max="10" class="form-control input-sm rounded-0" value="<?php echo $student->scores? $student->scores->ca2: 0; ?>">
</div>
<div class="col-lg-1" id="assg">
<label>ca3</label>
<input type="number" name="ca3[]" min="0" max="10" class="form-control input-sm rounded-0" value="<?php echo $student->scores? $student->scores->ca3: 0; ?>">
</div>
<div class="col-lg-1" id="exam">
<label>Exam</label>
<input type="number" name="exam[]" min="0" max="70" class="form-control input-sm rounded-0" value="<?php echo $student->scores? $student->scores->exam: 0; ?>">
</div>
<div class="col-lg-1">
<label>Total</label>
<output class="result"></output>
</div>
</div>
<?php } ?>

in your view in form you have two input fields named session_id ↓↓
<input type="hidden" name="session_id" value="<?php echo $student->session_id; ?>">
<input type="hidden" name="session_id" value="<?php echo $sessionID; ?>">
Duplicate fields can cause issues, check which one has the correct
value in it and discard the other one. If both of the fields have
wrong values then check where the values are being initialized and so
on. This is how you debug in PHP.

Related

Unable to get value in payumoney success response, which is passed from controller method

I have integrated payumoney payment gateway in my project and it was working fine, but I have additional requirements so I want to pass is an id. I am getting the ID like this '$this->input->post('id'), and assign it the variable $plan_info and pass it to the confirmation page(view page), when the user clicks on the confirm button, the payment will be done by debit/netbanking. In the success page, I am not getting $plan_info value however I am passing to the confirmation page.
Code written in controller
$product_info = 'testTransaction';
$customer_name = $this->input->post('customer_name');
$customer_email = $this->input->post('customer_email');
$customer_mobile = $this->input->post('mobile_number');
$id = $this->input->post('id');
$customer_address = $this->input->post('customer_address');
$MERCHANT_KEY = "xyz";
$SALT = "xyzxyz";
$txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
//optional udf values
$udf1 = '';
$udf2 = '';
$udf3 = '';
$udf4 = '';
$udf5 = '';
$hashstring = $MERCHANT_KEY . '|' . $txnid . '|' . $amount . '|' . $product_info . '|' . $customer_name . '|' . $customer_email . '|'. $udf1 . '|' . $udf2 . '|' . $udf3 . '|' . $udf4 . '|' . $udf5 . '||||||' . $SALT;
$hash = strtolower(hash('sha512', $hashstring));
$success = base_url() . 'Success';
$fail = base_url() . 'Success';
$cancel = base_url() . 'Success';
$data = array(
'mkey' => $MERCHANT_KEY,
'tid' => $txnid,
'hash' => $hash,
'amount' => $amount,
'name' => $customer_name,
'productinfo' => $product_info,
'mailid' => $customer_email,
'phoneno' => $customer_mobile,
'address' => $customer_address,
'action' => "https://test.payu.in", //for live change action
https://secure.payu.in
'sucess' => $success,
'failure' => $fail,
'cancel' => $cancel,
'plan_info'=>$id // This value which is passed to confirm page should get back in payment success response
);
$this->load->view('confirmation', $data);
code written in view file
<div class="card-body">
<form action="<?php echo $action; ?>/_payment" method="post" id="payuForm" name="payuForm">
<input type="hidden" name="key" value="<?php echo $mkey; ?>" />
<input type="hidden" name="hash" value="<?php echo $hash; ?>"/>
<input type="hidden" name="txnid" value="<?php echo $tid; ?>" />
<div class="form-group">
<label class="control-label">Total Payable Amount</label>
<input class="form-control" name="amount" value="<?php echo $amount; ?>" readonly/>
</div>
<div class="form-group">
<label class="control-label">Your Name</label>
<input class="form-control" name="firstname" id="firstname" value="<?php echo $name; ?>" readonly/>
</div>
<div class="form-group">
<label class="control-label">Email</label>
<input class="form-control" name="email" id="email" value="<?php echo $mailid; ?>" readonly/>
</div>
<div class="form-group">
<label class="control-label">Phone</label>
<input class="form-control" name="phone" value="<?php echo $phoneno; ?>" readonly />
</div>
<div class="form-group">
<label class="control-label"> Booking Info</label>
<input class="form-control" name="productinfo" value="<?php echo $productinfo; ?>" readonly />
<input type="hidden" class="form-control" name="plan_info" value="<?php echo $plan_info; ?>" />
</div>
<div class="form-group">
<label class="control-label">Address</label>
<input class="form-control" name="address1" value="<?php echo $address; ?>" readonly/>
</div>
<div class="form-group">
<input name="surl" value="<?php echo $sucess; ?>" size="64" type="hidden" />
<input name="furl" value="<?php echo $failure; ?>" size="64" type="hidden" />
<!--for test environment comment service provider -->
<input type="hidden" name="service_provider" value="payu_paisa" size="64" />
<input name="curl" value="<?php echo $cancel; ?> " type="hidden" />
</div>
<div class="form-group float-right">
<input type="submit" value="Pay Now" class="btn btn-success" />
</div>
</form>
</div>
My requirement
1) How do I pass the value inside udf1 (If I pass in $udf1 then I am getting a checksum error).
2) If the $planinfo variable passed separately (not in $udf1) then how to get that value in success page (I have tried echo '<pre>'; print_r($_POST); exit();) all values are getting except $plan_info value.
So how do I get plan info value and how can I pass in any value in uf1 without getting a checksum error
assign the $udf1 = $id before $hashstring
Pass the $udf1 value in $data array eg
$data =array('udf1' => $id,..)
Add/Pass the udf1 value in view page also.

Display field from different table in a input form

How would I display student.Student instead of student_id
<?php
for ($i = 0; $i < $chkcount; $i++) {
$id = $chk[$i];
$res = $MySQLiconn->query("SELECT Student.ID, student.Student, student.School,student.PR, Jumps.dis_ft_1, Jumps.dis_in_1, Jumps.dis_ft_2, Jumps.dis_in_2, Jumps.dis_ft_3, Jumps.dis_in_3, Jumps.dis_ft_4, Jumps.dis_in_4, Jumps.dis_ft_5, Jumps.dis_in_5, Jumps.dis_ft_6, Jumps.dis_in_6
FROM Student LEFT JOIN Jumps ON Student.ID = Jumps.student_id WHERE ID=" . $id);
while ($row = $res->fetch_array()) {
?>
<tr>
<td>
<input type="hidden" name="id[]" value="<?php echo $row['ID']; ?>"/>
Student ID: <input type="text" name="st[]" value="<?php echo $row['student_id']; ?>"
class="form-control"/>
Attempt 1 <input type="text" name="df1[]" value="<?php echo $row['dis_ft_1']; ?>"
class="form-control"/>
<input type="text" name="di1[]" value="<?php echo $row['dis_in_1']; ?>"
class="form-control"/>
Attempt 2 <input type="text" name="df2[]" value="<?php echo $row['dis_ft_2']; ?>"
class="form-control"/>
<input type="text" name="di2[]" value="<?php echo $row['dis_in_2']; ?>"
class="form-control"/>
Attemp 3 <input type="text" name="df3[]" value="<?php echo $row['dis_ft_3']; ?>"
class="form-control"/>
<input type="text" name="di3[]" value="<?php echo $row['dis_in_3']; ?>"
class="form-control"/>
Attempt 4 <input type="text" name="df4[]" value="<?php echo $row['dis_ft_4']; ?>"
class="form-control"/>
<input type="text" name="di4[]" value="<?php echo $row['dis_in_4']; ?>"
class="form-control"/>
Attempt 5 <input type="text" name="df5[]" value="<?php echo $row['dis_ft_5']; ?>"
class="form-control"/>
<input type="text" name="di5[]" value="<?php echo $row['dis_in_5']; ?>"
class="form-control"/>
Attempt 6 <input type="text" name="df6[]" value="<?php echo $row['dis_ft_6']; ?>"
class="form-control"/>
<input type="text" name="di6[]" value="<?php echo $row['dis_in_6']; ?>"
class="form-control"/>
</td>
</tr>
<?php
}
}
?>
Not sure it can be done. But Student name would be better than student id.
Wouldn't post with more text so just typing so it will post.
I am learning PHP.
If there is only one field called Student i.e Student.Student, then you could just output the name <?php echo $row['Student']; ?>.
However, if there are ever name clashes, you can always give the field a new name for PHP to access.
SELECT Student.ID, Student.Student AS some_new_name FROM ....
<?php echo $row['some_new_name']; ?>

Trying to update database but the form only inserts blank entries

I have a site where the user registers and logs in and then is taken to a page to enter data.
I have successfully been able to recall all the fields in the database as input values into my form and I want to be able to update these values with a save button before submitting.
I have two form buttons providing different actions based on javascript.
I don't receive any errors but when I hit the save button no entries submit to my database.
I am pulling the unique key (email address) from the database and am trying to update all of the fields associated with the row the unique email address is in. I have this field as a hidden input that gets added to the submission when the save button is clicked.
Ive tried REPLACE, ON DUPLICATE KEY UPDATE to update the entry but it still does nothing. Here is my code:
<div style="float:left; width:450px;">
<form id="parts" class="form" name="parts" method="post" ><br>
<input type="hidden" id="email" name="email" value="<? echo $_SESSION['MM_Username']; ?>">
<input type="hidden" id="first_name" name="first_name" value="<? echo $user['first_name']; ?>">
<input type="hidden" id="last_name" name="last_name" value="<? echo $user['last_name']; ?>">
<input type="hidden" id="business_name" name="business_name" value="<? echo $user['business_name']; ?>">
<input type="hidden" id="occupation" name="occupation" value="<? echo $user['occupation']; ?>">
<input type="hidden" id="business_address_1" name="business_address_1" value="<? echo $user['business_address_1']; ?>">
<input type="hidden" id="business_address_2" name="business_address_2" value="<? echo $user['business_address_2']; ?>">
<input type="hidden" id="country" name="country" value="<? echo $user['country']; ?>">
<input type="hidden" id="city" name="city" value="<? echo $user['city']; ?>">
<input type="hidden" id="state_province" name="state_province" value="<? echo $user['state_province']; ?>">
<input type="hidden" id="zip" name="zip" value="<? echo $user['zip']; ?>">
<input type="hidden" id="phone" name="phone" value="<? echo $user['phone']; ?>">
<input type="hidden" id="special_offers" name="special_offers" value="<? echo $user['special_offers']; ?>">
<div id="div1"> </div>
<div id="div2">SET PART #</div>
<div id="div3">INSTALL DATE</div>
<div id="div1">1.</div>
<div id="div2"><input type="text" id="part_1" name="part_1" value="<? echo $user['part_1']; ?>"> </div>
<div id="div3"><input type="text" id="part_1_install_date" name="part_1_install_date" value="<? echo $user['part_1_install_date']; ?>"> </div>
<div id="div1">2.</div>
<div id="div2"><input type="text" id="part_2" name="part_2" value="<? echo $user['part_2']; ?>"></div>
<div id="div3"><input type="text" id="part_2_install_date" name="part_2_install_date" value="<? echo $user['part_2_install_date']; ?>"></div>
<div id="div1">3.</div>
<div id="div2"><input type="text" id="part_3" name="part_3" value="<? echo $user['part_3']; ?>"></div>
<div id="div3"><input type="text" id="part_3_install_date" name="part_3_install_date" value="<? echo $user['part_3_install_date']; ?>"></div>
<div id="div1">4.</div>
<div id="div2"><input type="text" id="part_4" name="part_4" value="<? echo $user['part_4']; ?>"></div>
<div id="div3"><input type="text" id="part_4_install_date" name="part_4_install_date" value="<? echo $user['part_4_install_date']; ?>"></div>
<div id="div1">5.</div>
<div id="div2"><input type="text" id="part_5" name="part_5" value="<? echo $user['part_5']; ?>"></div>
<div id="div3"><input type="text" id="part_5_install_date" name="part_5_install_date" value="<? echo $user['part_5_install_date']; ?>"></div>
<div id="div1">6.</div>
<div id="div2"><input type="text" id="part_6" name="part_6" value="<? echo $user['part_6']; ?>"></div>
<div id="div3"><input type="text" id="part_6_install_date" name="part_6_install_date" value="<? echo $user['part_6_install_date']; ?>"></div>
<div id="div1">7.</div>
<div id="div2"><input type="text" id="part_7" name="part_7" value="<? echo $user['part_7']; ?>"></div>
<div id="div3"><input type="text" id="part_7_install_date" name="part_7_install_date" value="<? echo $user['part_7_install_date']; ?>"></div>
<div id="div1">8.</div>
<div id="div2"><input type="text" id="part_8" name="part_8" value="<? echo $user['part_8']; ?>"></div>
<div id="div3"><input type="text" id="part_8_install_date" name="part_8_install_date" value="<? echo $user['part_8_install_date']; ?>"></div>
<div id="div1">9.</div>
<div id="div2"><input type="text" id="part_9" name="part_9" value="<? echo $user['part_9']; ?>"></div>
<div id="div3"><input type="text" id="part_9_install_date" name="part_9_install_date" value="<? echo $user['part_9_install_date']; ?>"></div>
<div id="div1">10.</div>
<div id="div2"><input type="text" id="part_10" name="part_10" value="<? echo $user['part_10']; ?>"></div>
<div id="div3"><input type="text" id="part_10_install_date" name="part_10_install_date" value="<? echo $user['part_10_install_date']; ?>"></div>
<div id="div1"> </div>
<div id="div2"><input type="submit" name="save" value="Save" onclick="submitForm('save.php')"></div>
<div id="div3"><input class="send" id="register" type="submit" value="Submit" onclick="submitForm('submit.php')" disabled="disabled"></div>
</form>
LOGOUT
</div>
Here is my save button onclick action:
<?php
include("includes/connection.php");
$sql = "INSERT INTO login (email, first_name, last_name, business_name, occupation, business_address_1, business_address_2, country, city, state_province, zip, phone, special_offers, part_1, part_1_install_date, part_2, part_2_install_date, part_3, part_3_install_date, part_4, part_4_install_date, part_5, part_5_install_date, part_6, part_6_install_date, part_7, part_7_install_date, part_8, part_8_install_date, part_9, part_9_install_date, part_10, part_10_install_date)
VALUES ('$_POST[email]','$_POST[first_name]','$_POST[last_name]','$_POST[business_name]','$_POST[occupation]','$_POST[business_address_1]','$_POST[business_address_2]','$_POST[country]','$_POST[city]','$_POST[state_province]','$_POST[zip]','$_POST[phone]','$_POST[special_offers]','$_POST[part_1]', '$_POST[part_1_install_date]', '$_POST[part_2]', '$_POST[part_2_install_date]', '$_POST[part_3]', '$_POST[part_3_install_date]', '$_POST[part_4]', '$_POST[part_4_install_date]', '$_POST[part_5]', '$_POST[part_5_install_date]', '$_POST[part_6]', '$_POST[part_6_install_date]', '$_POST[part_7]', '$_POST[part_7_install_date]', '$_POST[part_8]', '$_POST[part_8_install_date]', '$_POST[part_9]', '$_POST[part_9_install_date]', '$_POST[part_10]', '$_POST[part_10_install_date]')
ON DUPLICATE KEY UPDATE login SET column = 'email' WHERE column='$_POST[email]'";
if (mysqli_query($connection, $sql)) {
echo header('Location: login-ENG.php');
} else {
echo mysqli_error($connection);
}
mysqli_close($connection);
?>
Here is the javascript to differentiate button functions:
<script>
function submitForm(action)
{
document.getElementById('parts').action = action;
document.getElementById('parts').submit();
}
</script>
NONE of your form fields have name attributes. Without name=..., there's nothing to submit. id attributes are not relevant at all for form submission. A simple var_dump($_POST) would have shown you this.
<input type="text" name="email" ... />
^^^^^^^^^^^^
|
VALUES ('$_POST[email]','$
As well, you are vulnerable to sql injection attacks

Post request is not sending all variables

I have a form which consists of rows set up like:
<div class="row unit" onmouseover="this.style.background = '#eeeeee';" onmouseout="this.style.background = 'white';" onclick="if(event.srcElement.nodeName != 'INPUT' && event.srcElement.nodeName != 'SELECT' && event.srcElement.nodeName != 'TEXTAREA'){goToByScroll(event.srcElement,-160);}">
<div class="col">
<div class="select">
<input type="checkbox" id="select<?php echo $i; ?>" name="select<?php echo $i; ?>">
</div>
</div>
<div class="col name">
<p><input class="searchable" type="text" id="name<?php echo $i; ?>" name="name<?php echo $i; ?>" value="<?php echo $name; ?>"></p>
<p>Badge ID: <input class="searchable" type="text" id="badge<?php echo $i; ?>" name="badge<?php echo $i; ?>" value="<?php echo $badge; ?>" style="width: 50px;"></p>
</div>
<div class="col phone">
<p>Work: <input class="searchable" type="text" id="phone<?php echo $i; ?>" name="phone<?php echo $i; ?>" value="<?php echo $phone; ?>"></p>
<p>Cell: <input class="searchable" type="text" id="cell<?php echo $i; ?>" name="cell<?php echo $i; ?>" value="<?php echo $cell; ?>"></p>
<p>Home: <input class="searchable" type="text" id="home<?php echo $i; ?>" name="home<?php echo $i; ?>" value="<?php echo $home; ?>"></p>
</div>
<div class="col email">
<p>Work: <input class="searchable" type="text" id="email<?php echo $i; ?>" name="email<?php echo $i; ?>" value="<?php echo $email; ?>"></p>
<p>Personal: <input class="searchable" type="text" id="perEmail<?php echo $i; ?>" name="perEmail<?php echo $i; ?>" value="<?php echo $perEmail; ?>"></p>
</div>
<div class="col file">
<p class="removeFile"><input type="text" id="filename<?php echo $i; ?>" name="filename<?php echo $i; ?>" class="file" value="<?php echo $filename; ?>" readonly>
Remove: <input type="checkbox" id="removeFile<?php echo $i; ?>" name="removeFile<?php echo $i; ?>"></p>
<input type="file" id="file<?php echo $i; ?>" name="file<?php echo $i; ?>" onchange="myForm.elements['filename<?php echo $i; ?>'].value=myForm.elements['file<?php echo $i; ?>'].value;">
</div>
</div>
These rows get repeated using a javascript function which increments the name:
function addTableRow(table){
for(i=0; i<myForm.elements['entriesNum'].value; i++){
var $tr = $(table).find(".row:last").clone();
$tr.find("input,select,textarea").attr("name", function(){
var parts = this.id.match(/(\D+)(\d+)$/);
return parts[1] + ++parts[2];
}).attr("id", function(){
var parts = this.id.match(/(\D+)(\d+)$/);
return parts[1] + ++parts[2];
});
$(table).find(".row:last").after($tr);
$tr.find('.fileElements').remove();
$tr.find('input[type!="radio"], textarea').removeAttr("value");
$tr.find('input').removeAttr("checked");
$tr.find('select option:first-child').attr("selected", true);
$tr.find('input[type!="radio"]').removeAttr("disabled");
$tr.find('input[type="radio"]').attr("disabled", "disabled");
$tr.find('.error').hide();
}
}
This works perfectly until the number of rows gets higher than 111. At this point when I submit no more data gets included in the array no matter how many rows I add. I was able to deduce this by using print_r($_REQUEST);. I have edited my php.ini and set all the maxes to be absurdly high with still no change.
Whenever I've had issues with javascript created form elements not showing up in the POST, it's always had to do with the way I've structured the FORM tags.
Things to look for...
Is your FORM tag properly closed off?
Is your FORM start and close at the same level in the DOM? For example, you wouldn't want to do this...
<form method='post'>
<div>
<!--lots of stuff-->
</form>
</div>
You would instead want this...
<form method='post'>
<div>
<!--lots of stuff-->
</div>
</form>
Do you have another FORM tag that's opened and not closed before the one you're actually working with? Like this...
<form method='get'>
<!--some kind of form about something else-->
<form method='post'>
<!--the data you're currently focused on-->
</form>

Post data not being sent by a code igniter form

I've got a slight problem with my CI2.0.2 application.
From what I can tell, it is not getting any post data from a form and so is failing to run an update function, though most pages work fine.
The form is as follows:
<?php echo form_open('job/update/', array('id' => 'update', 'name' => 'update')); ?>
<div class="images">
<?php echo img('application/images/updateJob.png');?>
</div>
<h1>Update Job</h1>
<br><br><br><br>
<div class="fieldset">
<?php
if (isset($error))
{
echo '<div id ="error">';
echo '<h2>Error:</h2>';
echo '<p>'.$error.'</p>';
echo '</div>';
}
?>
<input type="hidden" name="c" id='c' value="<?php if(!empty($view[0])) { echo $view[0]; } else { echo "0"; } ?>">
<div class="left">
<h4>Job Details:</h4>
<div>
<label for="job_number">Job No:</label>
<input type="text" name="job_number" id="job_number" value="<?php echo $job['jobno']; ?>" disabled="disabled">
</div>
<div>
<label for="date">Date:</label>
<input type="text" name="date" id="date" value="<?php echo $job['datetime']->format('d-M-Y'); ?>">
</div>
<div>
<label for="council">Council:</label>
<input type="text" name="council" id="council" value="<?php echo htmlspecialchars($job['council']); ?>"> *
</div>
<div>
<label for="dano">DA No:</label>
<input type="text" name="dano" id="dano" value="<?php echo htmlspecialchars($job['dano']); ?>">
</div>
<div>
<label for="client">Client:</label>
<input type="text" name="client" id="client" value="<?php echo $job['clientid']; ?>" disabled="disabled">
</div>
</div>
<div class="right" style="margin-left: 390px;">
<h4>Location:</h4>
<label for="street_no">Street No:</label>
<input type="text" name="street_no" id="street_no" value="<?php echo $address['streetno']; ?>"> *
<br>
<label for="street_name">Street Name:</label>
<input type="text" name="street_name" id="street_name" value="<?php echo $address['streetname']; ?>"> *
<br>
<label for="street_type">Street Type:</label>
<select name="street_type" id="street_type">
<?php
foreach ($street_types as $type)
{
echo '<option';
if ($type == $address['streettype']) echo ' selected="selected"';
echo '>'.$type.'</option>';
}
?>
</select> *
<br>
<label for="suburb">Suburb:</label>
<input type="text" name="suburb" id="suburb" value="<?php echo $address['suburb']; ?>"> *
<br>
<label for="postcode">Postcode:</label>
<input type="text" name="postcode" id="postcode" value="<?php echo $address['postcode']; ?>"> *
<br>
<label for="state">State:</label>
<input type="text" name="state" id="state" value="<?php echo $address['state']; ?>"> *
<br>
<label for="country">Country:</label>
<input type="text" name="country" id="country" value="<?php echo $address['country']; ?>">
<br>
<label for="dp">DP:</label>
<input type="text" name="dp" id="dp" value="<?php echo $address['dp']; ?>">
<br>
<label for="lot_no">Lot No:</label>
<input type="text" name="lot_no" id="lot_no" value="<?php echo $address['lotno']; ?>">
<br>
<label for="po_box">PO Box:</label>
<input type="text" name="po_box" id="po_box" value="<?php echo $address['pobox']; ?>">
</div>
<div>
<input type="submit" id="submit" name="submit" value="Submit" class="button">
<p>* = Required fields</p>
</div>
</div>
<?php echo form_close();?>
And the update section of the controller is as follows:
/**
* Update an existing job.
* #param int $job_number The number of the job to update.
*/
public function update($job_number=0)
{
$this->load->model('Job_model');
$job = array();
$address = array();
// Get post data.
$job['joblocation'] = '';
$job['jobno'] = $this->input->post('job_number');
$job['datetime'] = new DateTime($this->input->post('date'));
$job['dano'] = $this->input->post('dano');
$job['council'] = $this->input->post('council');
echo $job['jobno'];
echo $job['dano'];
echo $job['council'];
$address['streetno'] = $this->input->post('street_no');
$address['streetname'] = $this->input->post('street_name');
$address['suburb'] = $this->input->post('suburb');
$address['country'] = $this->input->post('country');
$address['postcode'] = $this->input->post('postcode');
$address['state'] = $this->input->post('state');
$address['dp'] = $this->input->post('dp');
$address['lotno'] = $this->input->post('lot_no');
$address['pobox'] = $this->input->post('po_box');
$address['streettype'] = $this->input->post('street_type');
echo "here2";
if (isset($_POST['submit']))
{
$this->Job_model->update($job);
echo "here";
redirect('job/');
}
// Otherwise, get the data from the database.
else
{
$job = $this->Job_model->search($job_number);
$job = $job[0];
$job['datetime'] = new DateTime($job['datetime']);
$address = $this->Job_model->get_address($job['joblocation']);
$address = $address[0];
}
// Get the street types.
$street_types = array();
$this->load->model('staff_model');
$streets = $this->staff_model->get_street_types();
foreach ($streets as $street)
{
$street_types[$street['streettype']] = $street['streettype'];
}
// Load the client list.
$clients = array();
$this->load->model('client_model');
$people = $this->client_model->get_client_person_list();
$companies = $this->client_model->get_client_company_list();
// Allocate view data.
$viewdata = array();
$viewdata['job'] = $job;
$viewdata['street_types'] = $street_types;
$viewdata['address'] = $address;
$viewdata['people'] = $people;
$viewdata['companies'] = $companies;
$this->layout->view('job/update', $viewdata);
}
Any ideas why this might be happening?
Thanks in advance,
James
Try changing the quotes you're using on this line:
<input type="hidden" name="c" id='c' value="<?php if(!empty($view[0])) { echo $view[0]; } else { echo '0'; } ?>" />
The way you had it with the double quotes around the 0 you were breaking that php because the first one would be closing the opening value quote.

Categories