2016-04-27 45 views
1

我想使貨幣轉換器。如何使用字符串值

$number1=""; 
$number3=""; 
<form method="POST"> 
    <select id="dc1" name="dc1"> 
     <option value="9777.31">SGD</option> 
    </select> 

    <input type="text" name="text1" value="<?php echo $nilai1?>"> 

    <select id="dc2" name="dc2"> 
     <option value="13190" >USD</option> 
     <input type="submit" name="calculate" value="calculate"> 
    </select> 
</form> 
<?php  
if(isset($_POST['calculate']))  
{  
if($_POST['dc1'] && $_POST['dc2'])  
{ 
    $number1 = $_POST['text1']; 
    $one = $_POST['dc1']; 
    $two = $_POST['dc2']; 

    $x = $number1/($two/$one); 
    $number3 = $x; 
}else{ 
    $number3 = "fail"; 
} 
} 
?> 
<input type="text" name="text2" value="<?php echo $number3?>"> 

它確定這些代碼,但是當我試圖改變這樣的?

$number1=""; 
$number3=""; 
$test=9777.31; 
<form method="POST"> 
    <select id="dc1" name="dc1"> 
     <option value="<?php $test?>">SGD</option> 
    </select> 

$number3結果是"fail",其我的代碼那麼糟糕嗎?或者我忘了什麼?

+0

對於你有一個'select'塊內的'input'標籤開始。並且您擁有PHP代碼之外的PHP代碼。 –

回答

2

試試這個:

$number1=""; 
$number3=""; 
$test=9777.31; 
<form method="POST"> 
    <select id="dc1" name="dc1"> 
     <option value="<?php echo $test?>">SGD</option> 
    </select> 
+0

謝謝先生,它的工作:D – Pentolan

相關問題