2017-05-03 2 views
1

저는 PHP를 배우기위한 간단한 PHP 폼을 가지고 있습니다. 튜토리얼의 코드가 있습니다. 내 HTML은 다음과 같습니다POST 할 수 없습니다.

<form action="php/learnphp.php" method="post"> 
    <table border="0"> 
     <tr> 
      <td>Name</td> 
      <td align="center"> 
       <input type="text" name="username" size="30" /> 
      </td> 
     </tr> 

     <tr> 
      <td>Address</td> 
      <td align="center"> 
       <input type="text" name="streetaddress" size="30" /> 
      </td> 
     </tr> 

     <tr> 
      <td>City</td> 
      <td align="center"> 
       <input type="text" name="cityaddress" size="30" /> 
      </td> 
     </tr> 

     <tr> 
      <td colspan="2" align="center"> 
       <input type="submit" value="Submit" /> 
      </td> 
     </tr> 

    </table> 
</form> 

내 PHP 파일은 다음과 같습니다 /php/learnphp.php 게시 할 수 없습니다 :

<?php 

     $usersName = $_POST['username']; 
     $streetAddress = $_POST['streetaddress']; 
     $cityAddress = $_POST['cityaddress']; 

     echo '<p>Your Information</p>'; 

     // You can combine variables with text using a . 

     echo $usersName. ' lives at </br>'; 
     echo $streetAddress. ' in </br>'; 
     echo $cityAddress. '</br></br>';  ?> 

난라는 오류가 제출 버튼을 누르면.

나는 루트 맵에 'php'라는 맵을 가지고있다. 나는 아마 그것이 정말로 간단하다는 것을 알고있다. 그러나 나는 그것을 이해할 것 같지 않다.

+0

learnphp.php 및 HTML 관련 파일은 다른가요? – rahulsm

+0

예 2 파일이 있습니다 : 첫 번째는 html로 양식, 두 번째는 learnphp.php입니다 – Rikkers

+0

learnphp.php는 폴더 php에 있습니까? 파일의 위치를 ​​모두 공유 할 수 있습니까 – rahulsm

답변

0

경로 폴더가 잘못되었을 수 있습니다. <yourhtmlfile>.html과 같은 레벨 인 learnphp.php과 같은 레벨을 만들어보십시오. 예 root/learnphp.phproot/<yourhtmlfile>.html. 그리고 양식을 편집해야합니다.

<form action="learnphp.php" method="post"> 
+0

해봤지만 같은 오류가 발생합니다. 나는 "learnphp.php"로 양식 동작을 변경했습니다 – Rikkers

+0

이게 도움이 될지 모르겠지만 시도해보십시오. 양식에 이름과 제출 버튼을 추가합니다. – JunieL

+0

코드를 시험해 보았고 내 지역에서 테스트를 마쳤습니다. 그래서 이상한 – JunieL

0

이 작업을 시도해주십시오. 저에게 도움이됩니다.

my.php

<form action="learnphp.php" method="post"> 
    <table border="0"> 
     <tr> 
      <td>Name</td> 
      <td align="center"> 
       <input type="text" name="username" size="30" /> 
      </td> 
     </tr> 

     <tr> 
      <td>Address</td> 
      <td align="center"> 
       <input type="text" name="streetaddress" size="30" /> 
      </td> 
     </tr> 

     <tr> 
      <td>City</td> 
      <td align="center"> 
       <input type="text" name="cityaddress" size="30" /> 
      </td> 
     </tr> 

     <tr> 
      <td colspan="2" align="center"> 
       <input type="submit" value="Submit" name="submit" /> 
      </td> 
     </tr> 
    </table> 
</form> 

learnphp.php

<?php 
if(isset($_POST["submit"])) 
{ 
    $usersName = $_POST['username']; 
    $streetAddress = $_POST['streetaddress']; 
    $cityAddress = $_POST['cityaddress']; 

    echo '<p>Your Information</p>'; 

     // You can combine variables with text using a . 

     echo $usersName. ' lives at </br>'; 
     echo $streetAddress. ' in </br>'; 
     echo $cityAddress. '</br></br>';  
} 
?> 
관련 문제