无法从PHP表单中读取$ _POST []值

时间:2011-09-05 07:10:48

标签: php html post

<?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>";

我的代码与上面的内容类似。我试图将sel + $ i(连接时为sel1)的值传递给php文件bossconfirm2.php。这是我的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;

每当我显示$sel1的值时,都不显示任何内容。我放了一个回音“HI
”;看看PHP语法是否有问题,但我发现$_POST[]无法访问表单。我尝试在文件末尾添加一个html语法,看看我是否可以使用此代码将值传递给$test

<td><input type='text' name='test'></td>

它有效。我使用纯PHP(echo ..etc)创建的表单似乎无法传递值。有人请告诉我如何才能使它发挥作用?

编辑: 这是我的完整代码

<?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='textBox' 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>

这是我的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');
?>

1 个答案:

答案 0 :(得分:0)

检查发布内容的一种方法是print_r($ _ POST)函数,它将打印发布值数组。

您还可以将此包装在预标签中,如下所示,以更易读的形式格式化输出,例如

<pre>
<?php print_r($_POST); ?>
</pre>