2015-04-06 91 views
1

所以,我有以下代碼:檢索texfield價值和發佈查詢

<input type="text" name="months"> 
<input class="button" type="submit" onclick="message()" value="Submit"/> 

<? 
$monthss=$_POST['months']; 
echo $monthss; 

$q = "Select to_char(tgl_val,'MM-YYYY') as tglmonth where bt_number=".$bt_number." and to_char(tgl_val,'MM-YYYY')=".$monthss." order by tglmonth asc"; 
$s2=OCIParse($c_slave,$q); 
//OCIBindByName($s2,":bind1",$ordernumber); 
OCIExecute($s2,OCI_DEFAULT); 

    echo "<tr><td>"; 
    echo "MONTH"; 
    echo "</td><td>"; 
    echo "AMOUNT"; 
    echo "</td><td>"; 
    echo "DISCOUNT_AMOUNT"; 
    echo "</td><td>"; 
    echo "SERVICES"; 
    echo "</td><td>"; 
    echo "TAX"; 
    echo "</td><td>"; 
    echo "TOTAL_AMOUNT"; 
    echo "</td><td>"; 
    echo "PRINT"; 
    echo "</td></tr>"; 


while (OCIFetch($s2)) 
{ 
    $V_TGLMONTH   = oci_result($s2,'TGLMONTH'); 
    $V_AMOUNT    = oci_result($s2,'AMOUNT'); 
    $V_DISCOUNT_AMOUNT = oci_result($s2,'DISCOUNT_AMOUNT'); 
    $V_SERVICES   = oci_result($s2,'SERVICES'); 
    $V_TAX    = oci_result($s2,'TAX'); 
    $V_TOTAL_AMOUNT  = oci_result($s2,'TOTAL_AMOUNT'); 

    echo "<tr><td>"; 
    echo "<a href=\"tgl.php?tmt=".substr($V_TGLMONTH,0,2)."&tmm=".substr($V_TGLMONTH,3,4)."\">"; 
    echo $V_TGLMONTH; 
    echo "</a>"; 
    echo "</td><td>"; 
    echo $V_AMOUNT; 
    echo "</td><td>"; 
    echo $V_DISCOUNT_AMOUNT; 
    echo "</td><td>"; 
    echo $V_SERVICES; 
    echo "</td><td>"; 
    echo $V_TAX; 
    echo "</td><td>"; 
    echo $V_TOTAL_AMOUNT; 
    echo "</td><td>"; 
    echo "PRINT"; 
    echo "</td></tr>"; 
} 
?> 

關鍵是我有文本框和按鈕。在我填入mm-yyyy並且點擊按鈕後,結果應顯示當月的所有記錄。但是當我用01-2014填充文本字段,然後單擊發生按鈕的按鈕。你們能幫助我嗎?

+0

在你的代碼,例如當心SQL注入的當使用'$ monthss'變量時。 – Jost 2015-04-06 07:38:02

回答

1

解決

這是我最後的html代碼:

<form name="myForm" action="#" onsubmit="return validateForm()" method="post"> 
<input type="text" name="months" placeholder="mm-yyyy"> 
<input class="button" type="submit" value="Submit"/> 

而且它的PHP代碼:

<? 
$months=$_POST['months']; 
echo "<br><strong>Selected Month: </strong>" .$months; 
echo "<br><br>"; 

$q = "Select AMOUNT, SERVICES, BILL_NO, ORDER_NUMBER, TOTAL_AMOUNT, to_char(PAY_DATE,'YYYY-MM-DD HH:MI:SS') as PAY_DATE from payment_final where bt_number=".$bt_number." and to_char(tgl_val,'MM-YYYY')='".$months."' order by bill_no"; 
?>