2011-11-05 204 views
0

任何人都可以檢查我的代碼爲什麼我收到這樣的提示?疑難解答「Notice:Undefined index」error

說明:未定義指數:ID在C:\ XAMPP \ htdocs中\ HRPO \模塊\報告\裘\ view_jo.php上線76

線76:

$id=$_GET['id']; 

這裏是第一個可能,而我得到我id

<?php 
echo "<dl>"; 
echo "<dt width = 200 id=\"label\">"."SSA"."</dt>"; 
echo "<dd align='right'>"; 
$result = mysql_query("SELECT ssa.first_name,ssa.SSA_ID 
FROM staffing_specialist_asst ssa 
left join jo_partner jp on jp.SSA_ID = ssa.SSA_ID 
group by first_name") or die(mysql_error()); 
$dropdown = "<select name=\"SSA_ID\" style=\"position:relative; left:-51px;\">\n"; 
while($row = mysql_fetch_assoc($result)) { 
$dropdown .= "\r\n<option value='{$row['SSA_ID']}'>{$row['first_name']}</option>"; 
} 
$dropdown .= "\r\n</select>"; 

echo $dropdown; 
echo "</dd>"; 
echo "</dl>"; 
?> 

和第二代碼,其中線76被發現:

<?php 

$id=$_GET['id']; 

if(isset($_POST['submit'])) 
{ 
    $datefrom = $_POST['timestamp']; 
    $dateto = $_POST['timestamp1']; 

    //echo $option; 


    $_SESSION['datefrom'] = $datefrom; 
    $_SESSION['dateto'] = $dateto; 



    if(($datefrom == NULL) || ($dateto == NULL)){ 
     echo "<SCRIPT LANGUAGE='javascript'> confirmationError() ;</SCRIPT>"; 
     exit(); 

    } 


$final =("SELECT distinct jp.receivedDate as rDate, ssa.first_name as saFName, ssa.last_name as saLName,job.client_order_number as joNum, 
     job.job_order_type as joType, job.job_title as joTitle, cl.name as clientName 
,ss.first_name as ssFName,ss.last_name as ssLName,jp.acknowledgeDate as aDate, stat.status as stat 
FROM staffing_specialist_asst ssa 
left join jo_partner jp on ssa.SSA_ID = jp.SSA_ID 
left join job_order job on jp.job_order_number = job.job_order_number 
left join jo_status stat on job.job_order_number = stat.job_order_number 
left join staffing_specialist ss on jp.SS_ID = ss.SS_ID 
left join client cl on job.client_ID = cl.client_ID 
where jp.receivedDate between '$datefrom1' and '$dateto1' 
and ssa.SSA_ID='$id' 
group by jp.receivedDate 
order by jp.receivedDate asc"); 

echo $final; 

$query = mysql_query($final); 

echo "<table>"; 

while($row = mysql_fetch_array($query)) 
{ 
    $rDate = $row['rDate']; 
    $saFName = $row['saFName']; 
    $saLName = $row['saLName']; 
    $joNum = $row['joNum']; 
    $joType = $row['joType']; 
    $joTitle = $row['joTitle']; 
    $clientName = $row['clientName']; 
    $ssFName = $row['ssFName']; 
    $ssLName = $row['ssLName']; 
    $aDate = $row['aDate']; 
    $stat = $row['stat']; 

    echo "<tr>"; 
    echo "<td width='150' colspan=\"1\" align=\"center\">".$rDate."</td>"; 
    echo "<td width='150' colspan=\"1\" align=\"center\">".$saFName."".$saLName."</td>"; 
    echo "<td width='150' colspan=\"1\" align=\"center\">".$joNum."</td>"; 
    echo "<td width='150' colspan=\"1\" align=\"center\">".$joType."</td>"; 
    echo "<td width='150' colspan=\"1\" align=\"center\">".$joTitle."</td>"; 
    echo "<td width='150' colspan=\"1\" align=\"center\">".$clientName."</td>"; 
    echo "<td width='150' colspan=\"1\" align=\"center\">".$ssFName."".$ssLName."</td>"; 
    echo "<td width='150' colspan=\"1\" align=\"center\">".$aDate."</td>"; 
    echo "<td width='150' colspan=\"1\" align=\"center\">".$stat."</td>"; 
    echo "</tr>"; 

} 

echo "</table>"; 

} 

?> 

在此先感謝所有的建議和幫助。

回答

1

$_GET['id']預計在URL中獲得變量'id'(即www.google.com?id=4然後$_GET['id']將等於4)。

爲了檢查獲取價值if (! empty($_GET)) {$id = $_GET['id']}

編輯之前避免這種情況,你可以這樣做:實際的錯誤最終是需要使用$_GET代替$_POST表單數據的可能性的假設。

+0

當我嘗試了你的建議,我得到這樣的錯誤:**注意:未定義的變量:id在C:\ xampp \ htdocs \ HRPO \ module \ reports \ jo \ view_jo.php在第158行。 158是在第二個代碼,** $最終查詢**這是**秩序由jp.receivedDate ** –

0

看起來像選擇框是SSA_ID但您使用的是$ _GET ['id'],請嘗試將其更改爲$ _GET ['SSA_ID'];

+0

我也試過,但仍然存在相同的問題。 –

+1

糾正我,如果我錯了,但如果選擇框的名稱正在通過發送然後他需要使用'$ _POST ['SSA_ID']'。 **編輯**我錯了,大聲笑......他可以通過獲得提交他的表格。我不會刪除他犯這個錯誤。 –

+1

@Alvin:嘗試'$ _REQUEST ['SSA_ID']' –