$_SESSION variables "disappear" after form is submitted - php

I stored values from a form in SESSION variables but it seems that they are emptied after if(isset($_POST['submit']) even though I can echo them earlier in my code. The code runs and the insert works except for $toto and $tata which are empty.
In the code below _id, master_label, client_label are inserted correctly. And the target table fields match so the error does not come from there.
<?php
session_start();
[...]
echo "<form id='organization' action='?' method='POST' enctype='multipart/form-data' >" ;
echo "<select name='organization' onchange='this.form.submit()'>"; //
echo '<option value="">Select ORGANIZATION</option>';
while ($row=mysqli_fetch_array($result00)) {
echo '<option value="'.$row['company_id'].'">'.$row['company_id'].'</option>';
}
echo "</select>";
echo "</form>";
$cie_ticker = $_POST['organization'] ;
$_SESSION['company_id'] = $cie_ticker ;
$sql="(SELECT company_id, databasefile, company_name FROM `settings` WHERE company_id='$cie_ticker') LIMIT 1";
$result=mysqli_query($connect,$sql) or die('Could not execute the query ' . mysqli_error()) ;
$data_bis=$result->fetch_array() ;
$_SESSION['selected_cie_id'] = $data_bis['company_id'];
$_SESSION['selected_cie_name'] = $data_bis['company_name'];
<form id='demoForm' action="?" method="POST" enctype="multipart/form-data" target="_top">
<?php
$file = fopen('./company/'.$cie_ticker.'/'.$_SESSION['selected_cie_db'], "r") ; // $file = fopen('./company/'.$_SESSION["company_id"].'/'.$_SESSION['selected_cie_db'], "r") ;
$headers=fgetcsv($file, 1000, "|");
fclose($file);
?>
<table id="user_table">
<tr><th>HEADERS </th><th>MASTER DB HEADERS</th></tr>
<?php foreach ($headers as $entete) {
$query01="SELECT master_label FROM `mastertable`";
$result01=mysqli_query($connect,$query01); ?>
<tr id="<?php echo $entete;?>">
<td> <?php echo $entete ?></td>
<td id="<?php echo $row['_id'];?>">
<?php
echo "<br>";
echo "<select name=".$entete.">";
echo '<option value="MASTER DATA">Select MASTER DATA</option>';
while ($row=mysqli_fetch_array($result01)) {
echo '<option value="'.$row['master_label'].'">'.$row['master_label'].'</option>';
}
echo "</select>";
?>
</td>
</tr>
<?php } ?>
</table>
<input id="checkBtn" type="submit" name="submitbutton" value="SAVE" class="button"/>
</form>
if(isset($_POST['submitbutton'])) {
$toto = $data_bis['company_id'] ;
$tata = $data_bis['company_name'];
$selected=$_POST;
foreach($selected as $x => $x_value) {
$query= $connect->prepare("INSERT INTO `mytable` (_id, master_label, client_label, org_label, client_id) VALUES ('',?,?,?,?) ");
$query->bind_param('ssss',$x_value, $x, $toto, $tata );
$query->execute();
}
}
?>

I have found the answer:
In this case one must add hidden input for the $_SESSION variables otherwise they were lost after submitting the form.

Related

Data not being able to be saved into database PHP

I have this problem here where when I press the Add button, it should save my selected choices into my table in database.
But when I press it, my table in database did not receive any data.
Did I do something wrong with my code? I need to find a right way to save the data into my designated table.
Any help would be greatly appreciated. Thanks
<?php
include "..\subjects\connect3.php";
//echo "Connection successs";
$query = "SELECT * FROM programmes_list";
$result = mysqli_query($link, $query);
?>
<form name = "form1" action="dropdownindex.php" method="post">
<table>
<tr>
<td>Select Pragramme</td>
<td>
<select id="programmedd" onChange="change_programme()">
<option>select</option>
<?php while($row=mysqli_fetch_array($result)) { ?>
<option value="<?php echo $row["ID"]; ?>"><?php echo $row["programme_name"]; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td>Select intake</td>
<td>
<div id="intake">
<select>
<option>Select</option>
</select>
</div>
</td>
</tr>
<tr>
<td>Select Subjects</td>
<td>
<div id="subject">
<select >
<option>Select</option>
</select>
</div>
</td>
</tr>
<input type="submit" value="Add" name="send">
</table>
</form>
<?php
if(isset($_POST['Add'])) {
//print_r($_POST);
$course1 = implode(',',$_POST['programmedd']);
$course2 = implode(',',$_POST['intake']);
$course3 = implode(',',$_POST['subject']);
$db->query("INSERT INTO programmes(programme_registered, intake_registered, subjects_registered)
VALUES (' ".$course1." ',' ".$course2." ', ' ".$course3." ' )");
echo $db->affected_rows;
}
?>
<script type="text/javascript">
function change_programme()
{
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","ajax.php?programme="+document.getElementById("programmedd").value,false);
xmlhttp.send(null);
document.getElementById("intake").innerHTML=xmlhttp.responseText;
if(document.getElementById("programmedd").value=="Select"){
document.getElementById("subject").innerHTML="<select><option>Select</option></select>";
}
}
function change_intake()
{
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","ajax.php?intake="+document.getElementById("intakedd").value,false);
xmlhttp.send(null);
document.getElementById("subject").innerHTML=xmlhttp.responseText;
}
</script>
//ajax.php
<?php
$dbhost = 'localhost' ;
$username = 'root' ;
$password = '' ;
$db = 'programmes' ;
$link = mysqli_connect("$dbhost", "$username", "$password");
mysqli_select_db($link, $db);
if (isset($_GET["programme"])) {
$programme = $_GET["programme"];
} else {
$programme = "";
}
if (isset($_GET["intake"])) {
$intake = $_GET["intake"];
} else {
$intake = "";
}
if ($programme!="") {
$res=mysqli_query($link, "select * from intakes where intake_no = $programme");
echo "<select id='intakedd' onChange='change_intake()'>";
echo "<option>" ; echo "Select" ; echo "</option>";
while($value = mysqli_fetch_assoc($res)) {
echo "<option value=".$value['ID'].">";
echo $value["intake_list"];
echo "</option>";
}
echo "</select>";
}
if ($intake!="") {
$res=mysqli_query($link, "select * from subject_list where subject_no = $intake");
echo "<select>";
echo "<option>" ; echo "Select" ; echo "</option>";
while($value = mysqli_fetch_assoc($res)) {
echo "<option value=".$value['ID'].">";
echo $value["subjects"];
echo "</option>";
}
echo "</select>";
}
?>
Your error is where you check for button click.
Change to this
If(isset($_POST['send']))
For future purposes and references, When doing the above, include the name attribute from your button and not the value attribute

How to Update Value Based on the Displayed row in MySQL and PHP

I'm trying to update my data in MySQL database using the displayed data from it. But I haven't much luck in figuring out what I'm doing wrong. I don't know how can I pass my data from my $rows in order for me to use it in my UPDATE SQL statement.
I just want to complete all the data before I clicked the save button.
Please see attached image for the output..
And also, I got a warning message like this.
WHenever I Clicked the Save Data button..
Notice: Undefined variable: reason in C:\xampp\htdocs\BTR\get_forms.php on line 109
Notice: Array to string conversion in C:\xampp\htdocs\BTR\get_forms.php on line 109
Can someone enlighten me.. How to do this.? Thank you..
<?php
require 'config.php';
$form_type = $_POST['form_type'];
if ($form_type == 'MCCV-F2'){
$region = $_POST['region'];
$province = $_POST['province'];
$municipality = $_POST['municipality'];
$barangay = $_POST['barangay'];
$period = $_POST['period'];
$form_type = $_POST['form_type'];
echo "NON COMPLIANT IN EDUCATION<br>";
echo "<br><br>MUNICIPALITY: ".$municipality;
echo "<br><br>BARANGAY: ".$barangay;
echo "<br><br>PERIOD: ".$period;
?>
<form name="get_forms_f2" action="" method="post">
<br><br>
<center><table border = 1 style =2 width=1800>
<tr>
<td><center><b>Household ID </center></td>
<td><center><b>Member ID </center></td>
<td><center><b>Name</center></td>
<td><center><b>Sex</center></td>
<td><center><b>HH Status</center></td>
<td><center><b>Grade Level </center></td>
<td><center><b>School ID</center></td>
<td><center><b>Name Of Dominant School</center></td>
<td><center><b>CV Remarks</center></td>
<td><center><b>Reason</center></td>
<td><center><b>Other Reason</center></td>
<td><center><b>Intervention</center></td>
</tr>
<?php
$sql = "SELECT A.family_id, A.barangay, A.person_id, A.gender, A.family_status, A.current_grade_level,
A.school_facility_id, A.school_facility_name, A.municipality, CONCAT(B.last_name, ', ',B.first_name) as 'name',
B.person_id,B.cv_remarks, B.reason, B.other_reason, B.intervention, B.status FROM roster AS A RIGHT JOIN compliance AS B ON A.person_id = B.person_id
WHERE B.period='$period' AND B.form_type='$form_type' AND A.municipality='$municipality' AND A.barangay='$barangay'";
$query=$conn->prepare($sql);
$query->execute();
$result= $query->fetchALL(PDO::FETCH_ASSOC);
$count=(int)$query->rowCount();
foreach ($result as $row){
$person_id[] = $row['person_id'];
echo "<tr>";
echo "<td>".$row['family_id']."</td>";
echo "<td>".$row['person_id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['gender']."</td>";
echo "<td>".$row['family_status']."</td>";
echo "<td>".$row['current_grade_level']."</td>";
echo "<td>".$row['school_facility_id']."</td>";
echo "<td>".$row['school_facility_name']."</td>";
echo "<td><input type='text' name='cv_remarks[]' value='".$row['cv_remarks']."'></td>";
echo "<td><select name='reason[]'>";
if (is_null($row['reason'])){
$sql2= "SELECT reason_code, reason_desc FROM reasons WHERE form_type ='2' ORDER BY reason_code ASC";
echo "<option value=''>SELECT REASON FOR Non-Compliance</option>";
foreach($conn->query($sql2) as $row2){
echo "<option value='".$row2['reason_desc']."'>".$row2['reason_code']." - ".$row2['reason_desc']."</option>";
}
}
if (!is_null($row['reason'])){
$sql2= "SELECT reason_code, reason_desc FROM reasons WHERE form_type ='2' ORDER BY reason_code ASC";
echo "<option value='".$row['reason']."'>".$row['reason']." (SELECTED)"."</option>";
foreach($conn->query($sql2) as $row2){
echo "<option value='".$row2['reason_desc']."'>".$row2['reason_code']." - ".$row2['reason_desc']."</option>";
}
}
echo "</select></td>";
echo "<td><input type='text' name='other_reason[]' value='".$row['other_reason']."'></td>";
echo "<td><input type='text' name='intervention[]' value='".$row['intervention']."'></td>";
echo "</tr>";
}
}
?>
</table></center><br><br>
<input type="submit" name="submit" value="Save Data">
<?php
$sql3 = "UPDATE compliance SET reason='{$reason}' WHERE person_id='{$person_id}' AND form_type='$form_type' AND period='$period'";
$query = $conn->prepare($sql3);
$query->execute();
?>
</form>
I have posted with the answer of how to update form with an array variable as a whole.
I have kept person,reason as array since you have added that alone as array().
<?php
require 'config.php';
if(isset($_POST['submit']))
{
for ($i=0; $i<count($_POST['person_id']); $i++)
{
$sql3 = "UPDATE compliance SET reason='".$_POST['reason'][$i]."' WHERE person_id='".$_POST['person_id'][$i]."' AND form_type='".$_POST['form_type']."' AND period='".$_POST['period']."'";
$query = $conn->prepare($sql3);
$query->execute();
}// end of For
}// end of IF
$form_type = $_POST['form_type'];
if ($form_type == 'MCCV-F2'){
$region = $_POST['region'];
$province = $_POST['province'];
$municipality = $_POST['municipality'];
$barangay = $_POST['barangay'];
$period = $_POST['period'];
echo "NON COMPLIANT IN EDUCATION<br>";
echo "<br><br>MUNICIPALITY: ".$municipality;
echo "<br><br>BARANGAY: ".$barangay;
echo "<br><br>PERIOD: ".$period;
?>
<form name="get_forms_f2" action="" method="post">
<br><br>
<center><table border = 1 style =2 width=1800>
<tr>
<td><center><b>Household ID </center></td>
<td><center><b>Member ID </center></td>
<td><center><b>Name</center></td>
<td><center><b>Sex</center></td>
<td><center><b>HH Status</center></td>
<td><center><b>Grade Level </center></td>
<td><center><b>School ID</center></td>
<td><center><b>Name Of Dominant School</center></td>
<td><center><b>CV Remarks</center></td>
<td><center><b>Reason</center></td>
<td><center><b>Other Reason</center></td>
<td><center><b>Intervention</center></td>
</tr>
<?php
$sql = "SELECT A.family_id, A.barangay, A.person_id, A.gender, A.family_status, A.current_grade_level,
A.school_facility_id, A.school_facility_name, A.municipality, CONCAT(B.last_name, ', ',B.first_name) as 'name',
B.person_id,B.cv_remarks, B.reason, B.other_reason, B.intervention, B.status FROM roster AS A RIGHT JOIN compliance AS B ON A.person_id = B.person_id
WHERE B.period='$period' AND B.form_type='$form_type' AND A.municipality='$municipality' AND A.barangay='$barangay'";
$query=$conn->prepare($sql);
$query->execute();
$result= $query->fetchALL(PDO::FETCH_ASSOC);
$count=(int)$query->rowCount();
foreach ($result as $row){
?>
<input type="hidden" name="person_id[]" value="<?php echo $row['person_id'];?>">
<input type="hidden" name="form_type" value="<?php echo $form_type; ?>">
<input type="hidden" name="period" value="<?php echo $period; ?>">
<?php
echo "<tr>";
echo "<td>".$row['family_id']."</td>";
echo "<td>".$row['person_id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['gender']."</td>";
echo "<td>".$row['family_status']."</td>";
echo "<td>".$row['current_grade_level']."</td>";
echo "<td>".$row['school_facility_id']."</td>";
echo "<td>".$row['school_facility_name']."</td>";
echo "<td><input type='text' name='cv_remarks[]' value='".$row['cv_remarks']."'></td>";
echo "<td><select name='reason[]'>";
if (is_null($row['reason'])){
$sql2= "SELECT reason_code, reason_desc FROM reasons WHERE form_type ='2' ORDER BY reason_code ASC";
echo "<option value=''>SELECT REASON FOR Non-Compliance</option>";
foreach($conn->query($sql2) as $row2){
echo "<option value='".$row2['reason_desc']."'>".$row2['reason_code']." - ".$row2['reason_desc']."</option>";
}
}
if (!is_null($row['reason'])){
$sql2= "SELECT reason_code, reason_desc FROM reasons WHERE form_type ='2' ORDER BY reason_code ASC";
echo "<option value='".$row['reason']."'>".$row['reason']." (SELECTED)"."</option>";
foreach($conn->query($sql2) as $row2){
echo "<option value='".$row2['reason_desc']."'>".$row2['reason_code']." - ".$row2['reason_desc']."</option>";
}
}
echo "</select></td>";
echo "<td><input type='text' name='other_reason' value='".$row['other_reason']."'></td>";
echo "<td><input type='text' name='intervention' value='".$row['intervention']."'></td>";
echo "</tr>";
}
}// end of MCCV-F2 form
?>
</table>
</center>
<br><br>
<input type="submit" name="submit" value="Save Data">
</form>
Hope so this would solve your problem br. have a try and let me know if any hindrance you find.

value is not appearing in the drop downlist

I have a php code that add/delete new row (tr)to the html table. One column(td) has text field and second column(td) has a drop down. Dropdown source is mysql table.
First row(tr) value are coming correctly. But dropdonwn list is null when I add new row(tr)
code is:
<html>
<head>
<title></title>
<style type="text/css">
input {
display: block; /* makes one <input> per line */
}
</style>
</head>
<?php
include 'dbconnection\dbconnection.php'; // Database connection
$count=1;
if(isset($_POST['btnadd']) == "ADD NEW ITEM") {
// add 1 to the row counter
if (isset($_POST['count'])) $count = $_POST['count'] + 1;
// set value for first load
else $count = 1;
}
if(isset($_POST['btnremove']) == "DELTE ITEM") {
// decrement the row counter
$count = $_POST['count'] - 1;
// set minimum row number
if ($count < 1) $count = 1;
}
?>
<body>
<!-- call same file on submit -->
<form name="form1" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php
$cdquery="select cmc_id,cmc_name from cat_main_category";
$result2=mysqli_query($conn,$cdquery) or die(mysqli_error());
echo '<table>';
// print $count rows
for ($i=1; $i<=$count; $i++) {
echo ' <tr> <td> <input type="text" name="text'.$i.'" align="center"> </td>';
echo '<td> <select id="basicgroup'.$i.'" name="basicgroup'.$i.'" onchange=reload(this.form)>';
echo '<option value=0>Select</option>';
while ($row=mysqli_fetch_array($result2)) {
$cdTitle=$row["cmc_name"];
$id=$row["cmc_id"];
//if($id==#$basicgroup){
echo "<option selected value=$id>
$cdTitle
</option>";
/*}
else{echo "<option value=$id>
$cdTitle
</option>""."<BR>";;*/
}
echo '</select></td></tr> ';
}
?>
</table>
<!-- you only need one set of buttons and only one counter for this script
because every button would do the same -->
<input type="submit" name="btnadd" id="btnadd" value="ADD NEW ITEM" >
<input type="submit" name="btnremove" id="btnremove" value="DELETE ITEM">
<input type="hidden" name="count" value="<?php echo $count; ?>">
</form>
</body>
</html>
After you executed MySQL query:
$result2=mysqli_query($conn,$cdquery) or die(mysqli_error());
Save the results in the array like:
$categories = [];
while ($row=mysqli_fetch_array($result2)) {
$categories[$row["cmc_id"]] = $row["cmc_name"]
}
Then in your main loop:
for ($i=1; $i<=$count; $i++) {
echo ' <tr> <td> <input type="text" name="text'.$i.'" align="center"> </td>';
echo '<td> <select id="basicgroup'.$i.'" name="basicgroup'.$i.'" onchange=reload(this.form)>';
echo '<option value=0>Select</option>';
foreach ($categories as $id => $cdTitle) {
echo "<option selected value=$id>
$cdTitle
</option>";
}
echo '</select></td></tr>';
}
You current problem is on the first iteration you exhausting your MySQL query with mysqli_fetch_array and second select is empty
Change
<?php
$cdquery="select cmc_id,cmc_name from cat_main_category";
$result2=mysqli_query($conn,$cdquery) or die(mysqli_error());
echo '<table>';
for ($i=1; $i<=$count; $i++) {
echo '<tr><td><input type="text" name="text'.$i.'" align="center"></td>';
echo '<td><select id="basicgroup'.$i.'" name="basicgroup'.$i.'" onchange=reload(this.form)>';
echo '<option value=0>Select</option>';
while ($row=mysqli_fetch_array($result2)) {
$cdTitle=$row["cmc_name"];
$id=$row["cmc_id"];
echo "<option selected value=$id>$cdTitle</option>";
}
echo '</select></td></tr>';
}
?>
</table>
To
<?php
echo '<table>';
for ($i=1; $i<=$count; $i++) {
$cdquery="select cmc_id,cmc_name from cat_main_category";
$result2=mysqli_query($conn,$cdquery) or die(mysqli_error());
echo '<tr><td><input type="text" name="text'.$i.'" align="center"></td>';
echo '<td><select id="basicgroup'.$i.'" name="basicgroup'.$i.'" onchange=reload(this.form)>';
echo '<option value=0>Select</option>';
while ($row=mysqli_fetch_array($result2)) {
$cdTitle=$row["cmc_name"];
$id=$row["cmc_id"];
echo "<option selected value=$id>$cdTitle</option>";
}
echo '</select></td></tr>';
}
?>
</table>
Put,
$cdquery="select cmc_id,cmc_name from cat_main_category";
$result2=mysqli_query($conn,$cdquery) or die(mysqli_error());
inside for loop.

How do I identify the selected value from a dropdown list in the $_POST array?

I have a droplist <select> list in html. How do I identify the selected value in the $_POST array after the user submits the form ?
<form action="subj_exec.php">
<?php
echo $_SESSION['SESS_MEMBER_ID'];
echo $_SESSION['SESS_FIRST_NAME'];
echo $_SESSION['SESS_LAST_NAME'];
?>
<br>
<select name = "subj_id">
<?php
while ($row = mysqli_fetch_array($result)) {
$subject_id = $row['id'];
$code = $row['code'];
$name = $row['name'];
echo '<option value=';
echo $subject_id;
echo '> ';
echo $name;
echo '</option>';
}
?>
</select>
<input type="submit" value="submit" name="submit" />
</form>
The subject_id is blank in another php file
echo $_POST['subject_id'] is blank.
Please help to identify the issue in the code.
Thanks,
The standard method for forms is GET, so you need to add method="POST" to your form.
get: Default. Appends the form-data to the URL in name/value pairs: URL?name=value&name=value
post: Sends the form-data as an HTTP post transaction
<form action="subj_exec.php" method="POST"> //<<<< added method
<?php
echo $_SESSION['SESS_MEMBER_ID'];
echo $_SESSION['SESS_FIRST_NAME'];
echo $_SESSION['SESS_LAST_NAME'];
?>
<br>
<select name = "subj_id">
<?php
while ($row = mysqli_fetch_array($result)) {
$subject_id = $row['id'];
$code = $row['code'];
$name = $row['name'];
?>
<option value="<?= $subject_id; ?>"><?= $name; ?></option>
<?php
}
?>
</select>
<input type="submit" value="submit" name="submit" />
In your file subj_exec.php, you can output the selected value with
echo $_POST['subj_id'];
Here you go :
index.php
<form action="subj_exec.php" method="POST">
<?php
echo $_SESSION['SESS_MEMBER_ID'];
echo $_SESSION['SESS_FIRST_NAME'];
echo $_SESSION['SESS_LAST_NAME'];
?>
<select name="subj_id">
<?php
while ($row = mysqli_fetch_array($result)) {
$subject_id = $row['id'];
$code = $row['code'];
$name = $row['name'];
echo '<option value="'.$subject_id.'">'.$name.'</option>';
}
?>
</select>
<input type="submit" value="submit" name="submit" />
subj_exec.php
<?php
error_reporting(E_ALL ^ E_NOTICE);
if(isset($_POST['submit'])) {
if(strlen($_POST['subj_id']) >= 1) {
$option = htmlentities($_POST['subj_id'], ENT_QUOTES, "UTF-8");
// Do Something here with $option
echo $option;
}else {
echo 'nothing selected.';
}
}
?>

undefined offset error

I want to display values retrieved from mysql in forms and in row by row format.
So i used the following code.
<?php
while($rows1 = mysql_fetch_array($result1)){
?>
<tr height="30" >
<?php $elyid = $rows1['id'] ?>
<form action="leaveactions.php" method="post" name="viewleave">
<td width="82"><?php echo $rows1['empid'];?></td>
<td><?php echo $rows1['name'];?></td>
<td><?php echo $rows1['leavetype'];?></td>
<td width="82"><?php echo $rows1['startdate']; ?></td>
<td width="82"><?php echo $rows1['enddate']; ?></td>
<td><?php echo $rows1['leavetype']; ?></td>
<td>
<input type="submit" name="<?php $rows1['id']; ?>" value="accept"/>
</td>
<td>
<input type="submit" name="reject" value="reject"/>
<input type="hidden" name="emplid" value="<?php echo $rows1['id'] ?>"/>
</td>
</tr>
<?php } ?>
and in leaveactions.php
$ii=0;
$query1 = "select * from applied_leaves where supervisorid ='".$employeeId."' and status='not approved'";
$result1 = mysql_query($query1) or die (mysql_error());
$num1 = mysql_numrows($result1);
while($rows1 = mysql_fetch_array($result1)) {
$ii++;
echo $_POST["$ii"];
if(isset($_POST['$ii'])){
echo "accepted "; echo $_POST['$ii'];
$updateEmp = "update applied_leaves set status='".$accept."' where id='$ii' " ;
$uresult = mysql_query($updateEmp) or die (mysql_error());
if($uresult != null){
echo "Assignment Added successfully<br>";
?>
View Added Details
<?php
} else {
echo "error";
}
}
}
?>
but when run i get
Notice: Undefined offset: 1
Notice: Undefined offset: 2
.
.
.
.
.
.
like that.
Please help me solving the problem.
Thanks in Advance
EDIT
the new code that is causing exception is
$iii=0;
while($rows1 = mysql_fetch_array($result1))
{
$iii++;
if( $_POST["accpt".$iii] ) {
echo "accepted ";
$updateEmp = "update applied_leaves set status='".$accept."' where id='$iii' " ;
$uresult = mysql_query($updateEmp) or die (mysql_error());
if($uresult != null){
echo "Assignment Added successfully<br>";
?>
View Added Details
<?php break;
}
}
}
I think your main error lies here:
<input type="submit" name="<?php $rows1['id']; ?>" value="accept"/>
Here you do not echo $rows1['id'], so if you have a look in the generated code, the name should be empty.
Correct this to
<input type="submit" name="<?php echo $rows1['id']; ?>" value="accept"/>
Furthermore in leaveactions.php you have the following code:
// ...
echo $_POST["$ii"];
if(isset($_POST['$ii'])){
echo "accepted "; echo $_POST['$ii'];
// ...
Here you should first check, whether the variable (here it is $_POST[$ii] - no " needed) before doing the output.
As a result of the previous error, $_POST[$ii] is not set, thus you get the notice on the first echo and never enter the if-clause afterward.
It's because the array position you are trying to access is empty(not available). Check whether the array position exist using isset method.
if( isset( $array['position'] )
{
//position exists
}
Just don't post your code here. Paste the line which is relevant to the error. At least try commenting the line where the error occurs.

Categories