2016-02-10 63 views
-6

我只想知道這段代碼是否正確,因爲某些原因,它不適合我,我不知道爲什麼。 如果您需要我告訴您有關我的問題或我的系統的更多信息,只需要求助!這些php函數是否正確?

<?php 
    function add($x,$y) { 
     $result= $x+$y; 
     return $result; 
    }; 

    $number1= $_POST['n_1']; 
    $number2= $_POST['n_2']; 
    echo $number1.「 + ".$number2." = ".add($number1,$number2); 

    for ($i=5;$i<=50;$i+=5) { 
     echo $i."</br>"; 
    }; 

    $j=10; 
    while ($j>0){ 
     echo $j.「</br>"; 
     $j--; 
    }; 
> 

<!DOCTYPE html> 
<html> 
    <head> 
    </head> 
    <body> 
     <form action=「thisfile.php" method="POST"> 
      <label for="fullname">Full name: </label> 
      <input type="text" name="fullname" size="20"></br> 
      <label for="data">Data: </label> 
      <textarea rows="5" name="data" cols="20"></textarea></br> 
      <label for="valid">Valid?: </label> 
      <input type="checkbox" name="valid" value="ON"></br> 
      <label for="color">Color: </label> 
      <input type="radio" value="blue" checked name="color">Blue 
      <input type="radio" value="red" checked name="color">Red</br> 
      <label for="month">Month: </label> 
      <select size="1" name="month"> 
       <option selected value="january">January</option> 
       <option value="february">February</option> 
       <option value="march">March</option> 
      </select></br> 
      <label for="n_1">Number 1: </label> 
      <input type="text" name="n_1" size="20"></br> 
      <label for="n_2">Number 2: </label> 
      <input type="text" name="n_2" size="20"></br> 
      <input type="submit" value="send" name="send"> 
     </form> 
    </body> 
</html> 

謝謝!

+0

簡短的回答是否 – Machavity

+1

你能解釋什麼不工作更清楚嗎?它看起來像你沒有正確關閉你的PHP標籤(?>而不是>),所以這是一個開始。 –

+2

在打開'<?php'標記error_reporting(E_ALL)後立即在文件頂部添加錯誤報告; ini_set('display_errors',1);'你有幾個語法問題,特別是引號。 –

回答

1

請檢查下面的代碼,有什麼不對,你沒有被註釋掉的代碼: -

<?php 
error_reporting(E_ALL); // check all error including warning and notice error too 
ini_set('display_errors',1); // display errors 
    function add($x,$y) { 
     $result= $x+$y; 
     return $result; 
    } // ; not needed 

    $number1= $_POST['n_1']; 
    $number2= $_POST['n_2']; 
    echo $number1." + ".$number2." = ".add($number1,$number2);// using 「 is wrong 

    for ($i=5;$i<=50;$i+=5) { 
     echo $i."</br>"; 
    } // ; not needed 

    $j=10; 
    while ($j>0){ 
     echo $j."</br>"; // using 「 is wrong 
     $j--; 
    }//; not needed 
?> <!-- closing error--> 

<!DOCTYPE html> 
<html> 
    <head> 
    </head> 
    <body> 
     <form action="thisfile.php" method="POST"> <!--// using 「 is wrong --> 
      <label for="fullname">Full name: </label> 
      <input type="text" name="fullname" size="20"></br> 
      <label for="data">Data: </label> 
      <textarea rows="5" name="data" cols="20"></textarea></br> 
      <label for="valid">Valid?: </label> 
      <input type="checkbox" name="valid" value="ON"></br> 
      <label for="color">Color: </label> 
      <input type="radio" value="blue" checked name="color">Blue 
      <input type="radio" value="red" checked name="color">Red</br> 
      <label for="month">Month: </label> 
      <select size="1" name="month"> 
       <option selected value="january">January</option> 
       <option value="february">February</option> 
       <option value="march">March</option> 
      </select></br> 
      <label for="n_1">Number 1: </label> 
      <input type="text" name="n_1" size="20"></br> 
      <label for="n_2">Number 2: </label> 
      <input type="text" name="n_2" size="20"></br> 
      <input type="submit" value="send" name="send"> 
     </form> 
    </body> 
</html> 

N ote: - 應用POST數據檢查(驗證)是您的責任,並將其與代碼一起添加。謝謝

+0

謝謝你!真的很感謝你的回答! –

1

1.刪除};使它只}

,正確的語法是:

<?php 

?> 

你有

<?php 

>