2015-01-20 4 views
0

PHP 파일에 양식 데이터를 게시하는 HTML 파일이 있습니다 (또는 어쨌든 가정되어 있습니다). HTML과 PHP 파일은 프로젝트의 같은 폴더에 있지만 양식을 제출하면 "리소스를 찾을 수 없습니다."라는 PHP 파일의 이름은 "patient_json.php"입니다.PHP 파일을 찾을 수 없습니다

그들은 PHP 파일이 될 수없는 이유를 내가 알아낼 수 없습니다 프로젝트의 같은 폴더에, 다시

<?php 

// check if all form data are submited, else output error message 
if(isset($_POST['fname']) && isset($_POST['lname']) && isset($_POST['bday']) && isset($_POST['location']) && isset($_POST['pat_ssn'])) { 
    // if form fields are empty, outputs message, else, gets their data 
    if(empty($_POST['fname']) || empty($_POST['lname']) || empty($_POST['bday']) || empty($_POST['location']) || empty($_POST['pat_ssn'])) { 
    echo 'All fields are required'; 
    } 
    else { 
    // adds form data into an array 
    $formdata = array(
     'firstname'=> $_POST['fname'], 
     'lastname'=> $_POST['lname'], 
     'bday'=> $_POST['bday'], 
     'location'=> $_POST['location'], 
     'ssn'=> $_POST['pat_ssn'] 
    ); 

    // encodes the array into a string in JSON format (JSON_PRETTY_PRINT - uses whitespace in json-string, for human readable) 
    $jsondata = json_encode($formdata, JSON_PRETTY_PRINT); 

    // saves the json string in "pat_data.txt" 
    // outputs error message if data cannot be saved 
    if(file_put_contents('pat_data.txt', $jsondata)) echo 'Data successfully saved'; 
    else echo 'Unable to save data in "formdata.txt"'; 
    } 
} 
else echo 'Form fields not submitted'; 

// path and name of the file 
$filetxt = 'pat_data.txt'; 

// check if the file exists 
if(file_exists($filetxt)) { 
    // gets json-data from file 
    $jsondata = file_get_contents($filetxt); 

    // converts json string into array 
    $arr_data = json_decode($jsondata, true); 

    // Now you can use the array $arr_data with json-data saved in text file 
    var_export($arr_data);  // Test to see the array 
} 
else echo 'The file '. $filetxt .' not exists'; 

// path and name of the file 
$filetxt = 'pat_data.txt'; 

// check if all form data are submited, else output error message 
if(isset($_POST['fname']) && isset($_POST['lname']) && isset($_POST['bday']) && isset($_POST['location']) && isset($_POST['pat_ssn'])) { 
    // if form fields are empty, outputs message, else, gets their data 
    if(empty($_POST['fname']) || empty($_POST['lname']) || empty($_POST['bday']) || empty($_POST['location']) || empty($_POST['pat_ssn'])) { 
    echo 'All fields are required'; 
    } 
    else { 
    // gets and adds form data into an array 
    $formdata = array(
     'firstname'=> $_POST['fname'], 
     'lastname'=> $_POST['lname'], 
     'bday'=> $_POST['bday'], 
     'location'=> $_POST['location'], 
     'ssn'=> $_POST['pat_ssn'] 
    ); 

    // path and name of the file 
    $filetxt = 'pat_data.txt'; 

    $arr_data = array();  // to store all form data 

    // check if the file exists 
    if(file_exists($filetxt)) { 
     // gets json-data from file 
     $jsondata = file_get_contents($filetxt); 

     // converts json string into array 
     $arr_data = json_decode($jsondata, true); 
    } 

    // appends the array with new form data 
    $arr_data[] = $formdata; 

    // encodes the array into a string in JSON format (JSON_PRETTY_PRINT - uses whitespace in json-string, for human readable) 
    $jsondata = json_encode($arr_data, JSON_PRETTY_PRINT); 

    // saves the json string in "pat_data.txt" 
    // outputs error message if data cannot be saved 
    if(file_put_contents('pat_data.txt', $jsondata)) echo 'Data successfully saved'; 
    else echo 'Unable to save data in "pat_data.txt"'; 
    } 
} 
else echo 'Form fields not submited'; 

?> 

:

여기 여기

@using OnboardingProject.App_Code 
@using OnboardingProject.Controllers 

@{ 
    ViewBag.Title = "Patients"; 
} 

<div class="title"> 
    <div> 
     <h1 style="float: left">@ViewBag.Title</h1> 
    </div> 
    <div class="rmm" style="float: right; display: inline-block"> 
     <ul> 
      <li><button id="NewPatient">New Patient</button></li> 
     </ul> 
    </div> 
</div> 
<div id="modal_content"> 
    <div id="modal_window" title="Complete the form below to add a new patient:"> 
     <div style="text-align: right;"><a id="modal_close" href="#">close <b>X</b></a></div> 

     <form id="add_patient" method="POST" action="patient_json.php" accept-charset="UTF-8"> 
     <p><label>First Name<strong>*</strong><br> 
     <input type="text" autofocus required size="48" id="fname" value=""></label></p> 
     <p><label>Last Name<strong>*</strong><br> 
     <input type="text" autofocus required size="48" id="lname" value=""></label></p> 
     <p><label>Birthdate (mm/dd/yyyy)<strong>*</strong><br> 
     <input type="text" autofocus required size="48" id="bday" value=""></label></p> 
     <p><label>Site Name<strong>*</strong><br> 
     <input type="text" autofocus required size="48" id="location" value=""></label></p> 
     <p><label>SSN<strong>*</strong><br> 
     <input type="text" autofocus required size="48" id="pat_ssn" value=""></label></p> 
     <p><input type="submit" id="addPatient" value="Add Patient"></p> 
     </form> 
    </div> 
</div> 
<div class="content"> 
    <div id="patient_table"> 
     <table id="patients"> 
      <tr> 
       <th id="p_name">Patient Name</th> 
       <th id="p_site">Site</th> 
       <th id="dob">Date of Birth</th> 
       <th id="ssn">SSN</th> 
       <th id="edits"></th> 
      </tr> 
     </table> 
    </div> 
</div> 
<script src="@Url.Content("~/Scripts/PatientInfo.js")" type="text/javascript"></script> 

내 PHP 파일 내 HTML입니다 발견 된 아이디어?

+0

된다. – andrew

+0

죄송합니다 그것은 유형 -o입니다. PHP 파일 이름은 patient_json.php입니다. 모두들 미안해! – AtlasBowler

답변

1

귀하의 HTML 코드에 patient_json.php에 제출하고 있습니다 (patient_data.php이 아님).

<form id="add_patient" method="POST" action="patient_data.php" accept-charset="UTF-8"> 
+0

죄송합니다 그것은 유형 -o입니다. PHP 파일 이름은 patient_json.php입니다. 죄송합니다 그 – AtlasBowler

0

당신은 당신의 PHP 파일의 이름 patient_data.php하지만 코드를 가지며,

양식을 "form_json.php"에 제출했지만 파일 이름이 "form_data.php"라고 말한 경우 해당 작업을 해당 이름으로 변경하십시오.

+0

미안 유형 O입니다. PHP 파일 이름은 patient_json.php입니다. 죄송합니다. – AtlasBowler

+0

스크립트가 여전히 작동하지 않거나 문제가 있습니까? –

+0

스크립트가 여전히 작동하지 않습니다. 그 질문을 타이핑 할 때 그것은 단지 타입 O였습니다. – AtlasBowler

0
:

<form id="add_patient" method="POST" action="patient_json.php" accept-charset="UTF-8"> 

이 동작은 양식 그래서 그것이 있어야로 이동합니다 페이지입니다 :

+1

양식 작업은 'patient_json.php'가 아니라 'form_json.php'입니다. –

+0

아, 미안하지만 고마워. –

+0

죄송합니다. PHP 파일 이름은 patient_json.php입니다. 죄송합니다 – AtlasBowler

1

PHP 스크립트는 주 메뉴로 들어 가지 않으므로 실패합니다. $ _POST 변수가 설정되지 않았습니다.) POST 양식의 필드는 id가 아닌 이름으로 참조됩니다.

추가 매개 변수로 바로 name = "fname"을 추가하고 id = "fname"바로 옆에 각 입력 필드를 추가하면됩니다. typpo, 양식이 메모에 따라, 당신이 원하는 바가 아니다 "patient_json.php"에 제출되어 그 않는

<input type="text" autofocus required size="48" id="fname" value=""> 

<input type="text" autofocus required size="48" id="fname" name="fname" value=""> 
+0

에 이름 매개 변수가 추가되었습니다. 여전히 "리소스를 찾을 수 없습니다"는 PHP 파일 – AtlasBowler

+0

스크립트의 파일 이름 인 action = "filename.php"이 PHP 파일의 올바른 이름인지 확인하십시오. 또한 폼에서 submit을 클릭 한 후 브라우저의 URL이 올바른 PHP 파일 이름을 가지고 있는지 확인하십시오. 마지막으로 PHP 파일이 올바른 위치에 서버에 업로드되었는지 확인하십시오. –

관련 문제