Can't read $_POST[] value from a PHP form
<?php
echo "<form action='bossconfirm2.php' method='post' name='bossex' onsubmit='blankCheck()' >";
echo "<td><select id='disapprove".$i."' name = 'sel".$i."'>
<option value = '".$row['LeaveID']."'>Approve</option>
<option value = '2'>Disapprove</option>
</select>".$i."</td>";
My Code goes something like the one above. I'm trying to pass the value of sel+$i (which would be sel1 when concatenated) to the php file bossconfirm2.php. Here's my code for bossconfirm2.php:
$se11 = $_POST['sel1'];
$se12 = $_POST['sel2'];
$se13 = $_POST['sel3'];
$test = $_POST['test'];
echo "HI<br>";
echo "<br> ".$test."<br>";
echo "Sel 1 <br>".$sel1."Sel 2<br>".$sel2."Sel 3 ".$sel3;
Whenever the I display the values for $sel1
, nothing appears. I placed an echo "HI
$_POST[]
just can't access the form. I tried adding an html syntax at the end of the file to see if I could pass a value to $test
with this code
<td><input type='text' name='test'></td>
and it worked. It seems that the form I created using pure PHP (echo ..etc) can't pass values. Somebody please enlighten me as to how I could make it work?
Edit: Here's my complete code
<?php
echo "<form action='bossconfirm2.php' method='post' name='bossex' onsubmit='blankCheck()' >";
include 'config.php';
include 'opendb.php';
$testing = $_REQUEST['parent_id'];
$appSql = "SELECT f.LeaveId, CONCAT(p.LastName, ', ', SUBSTRING(p.Firstname,1,1), '.') 'Name',
CONCAT(DATE_FORMAT(f.DateFrom, '%b %e, %Y'),
' (',x.Scope,')')'From' ,
CONCAT(DATE_FORMAT(f.DateTo, '%b %e, %Y'), ' (', y.Scope,')')'To',
t.Abbreviation, r.Reason
FROM hris.tblpersonaldata p, timesys.tblfiledleaves f, hris.tblgroupings h,
hris.tblsector_deptoroffice d, timesys.tblleaveapproval a, timesys.tblleavetypes t,
timesys.tbllkupreason r,
timesys.tbllkupscope x, timesys.tbllkupscope y
WHERE
f.ScopeFromID = x.ScopeID AND f.ScopeToID = y.ScopeID
AND p.ID = f.EmpID
AND p.ID = h.ID AND h.SectorDeptOrOfficeID = d.SectorDeptOrOfficeID
AND f.EmpID = a.empID
AND a.leaveStatusID = '2'
AND f.LeaveTypeID = t.LeaveTypeID
AND f.ReasonID = r.ReasonID
AND f.DateReceived > '2011-07-31'
GROUP BY f.LeaveID
ORDER BY f.LeaveID ASC
LIMIT 3";
$appSqlQ = mysql_query($appSql) or die(mysql_error());
$lol =mysql_query("SELECT approvalID FROM timesys.tblleaveapproval WHERE leaveStatusID = '2';");
$rwww = mysql_fetch_array($lol);
if(is_null($rwww[0]))
echo "No Pending Leave Approval";
else{
echo "<table >";
echo "<tr >";
echo "<td bgcolor = '888888'>Name</td>";
echo "<td bgcolor = '888888'>From</td>";
echo "<td bgcolor = '888888'>To</td>";
echo "<td bgcolor = '888888'>Leave Type</td>";
echo "<td bgcolor = '888888'>Reason</td>";
echo "<td bgcolor = '888888'>Approval</td>";
echo "</tr>";
$i = 1;
while($row = mysql_fetch_array($appSqlQ))
{
//$i = 1;
echo "<tr>";
echo "<td bgcolor = 'FFF111'>" . $row['Name'] . "</a></td>";
echo "<td>" . $row['From'] . "</td>";
echo "<td bgcolor = 'FFF111'>" . $row['To'] . "</td>";
echo "<td>" . $row['Abbreviation'] . "</td>";
echo "<td bgcolor = 'FFF111'>" . $row['Reason'] . "</td>";
echo "<td><select id='disapprove" . $i . "' name = 'sel" . $i . "'>
<option value = '" . $row['LeaveID'] . "'>Approve</option>
<option value = '2'>Disapprove</option>
</select>
" . $i . "
</td>";
echo "<td>
<div id='disss" . $i . "'>
<input size =18 class='text开发者_运维知识库Box' type='textbox' value='Reason for disapp...' name = 'box" . $i . "' id='a" . $i . "'>
</div>
</td>";
$i++;
echo "<br>";
echo "</tr>";
}
echo "<tr>";
//echo "<td><button onclick='test111();'>CLieck</button></td>";
echo "<td><input type='Submit' value='Submit'/></td>";
//echo "<td><input type='Reset' value='Reset' /></td>";
echo "</tr>";
}
echo "</form>";
?>
<td><input type='text' name='test'></td>
And here's my code for bossconfirm.php
<?php
include 'config.php';
include 'opendb.php';
session_start();
$sessionID = $_SESSION['id'];
$x = 0;
$checkValue = $_POST['value'];
$sel1 = $_POST['sel1'];
$sel2 = $_POST['sel2'];
$sel3 = $_POST['sel3'];
$test = $_POST['test'];
echo "HI<br>";
echo "<br> " . $test . "<br>";
echo "Sel 1 <br>" . $sel1 . "Sel 2<br>" . $sel2 . "Sel 3 " . $sel3;
$today = date('Y-m-d');
?>
One way to keep a check on what's being posted is the print_r($_POST) function which will print the array of post values.
You could also wrap this in pre tags as follows to format the output in a more readable form such as
<pre>
<?php print_r($_POST); ?>
</pre>
精彩评论