2013-10-28 3 views
0

그래서 나는 다음과 같은 코드를 가지고 :HTTP 500 오류

index.html을 : 나는 양식을 제출하려고 할 때마다

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Title</title> 
</head> 

<body> 
<form id="form1" name="form1" method="post" action="post.php"> 
<table width="597" class="formatTblClass"> 
<tr> 
<th colspan="4"></th> 
</tr> 
<tr><input type="hidden" name="filename" value="example" /></tr> 
<tr> 
<td width="99"><span>First Name</span></td> 
<td width="217"><input class="" type="text" name="firstname" id="firstname" /></td> 
<td width="99"><span>Last Name</span></td> 
<td width="211"><input class="" name="lastname" type="text" id="lastname" /></td> 
<td width="99"><span>Street Address</span></td> 
<td width="217"><input class="" type="text" name="streetaddress" id="streetaddress" /></td> 
<td width="99"><span>City</span></td> 
<td width="211"><input class="" name="city" type="text" id="city" /></td> 
<td width="99"><span>State</span></td> 
<td width="211"><input class="" name="state" type="text" id="state" /></td> 
<td width="99"><span>Phone Number</span></td> 
<td width="211"><input class="" name="phone" type="text" id="phone" /></td> 
<td width="99"><span>Email</span></td> 
<td width="211"><input class="" name="email" type="text" id="email" /></td> 
</tr> 

<tr> 
    <td colspan="4">Would you like to receive updates from Company?</td> 
    </tr> 
<tr> 
    <td colspan="4"><input id="optincompany" name="optincompany" type="checkbox" checked="yes" value="yes" />I want to receive updates from Company.<br /></td> 
</tr> 
<tr> 
    <td colspan="4">Would you like to receive updates from Dealer?</td> 
    </tr> 
<tr> 
    <td colspan="4"><input id="optindealer" name="optindealer" type="checkbox" checked="yes" value="yes" />I want to receive updates from Dealer.<br /></td> 
</tr> 

<tr> 
    <td colspan="4"> 
    <div align="center"> 
    <input type="submit" name="Submit" id="Submit" value="Submit" /> 
    <input type="reset" name="Reset" id="button" value="Reset" /> 
    </div></td> 
</tr> 
</table> 
</form> 
</body> 
</html> 

post.php

<?php 

$firstname = $_POST['firstname']; 
$lastname = $_POST['lastname']; 
$streetaddress = $_POST['streetaddress']; 
$city = $_POST['city']; 
$state = $_POST['state']; 
$phone = $_POST['phone']; 
$email = $_POST['email']; 
//$optindealer = $_POST['optindealer']; 
//$optincompany = $_POST['optincompany']; 

$optindealer = (strtolower($_POST['optindealer']) === 'yes') ? 'Y' : 'N'; 
$optincompany = (strtolower($_POST['optincompany']) === 'yes') ? 'Y' : 'N'; 



$filename = $_POST['filename'] . ".csv"; 

$today = date("YmdHis"); 


    $fp = fopen($filename, “a”); 

    $savestring = " " . "," . $today . "," . " " . "," . $firstname . “,” . $lastname . "," . "I" . $address . "," . $city . "," . $state . "," . $optindealer . "," . $today . "," . $phone . "," . $today . "," . $email . “,” . $optincompany . "," . $today; 
     echo $savestring; 
    fwrite($fp, $savestring); 
    fclose($fp); 



?> 

, 나는 500 Internal Server 오류 (HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.)를 얻는다. 그리고 나는 왜 그 이유인지 알 수 없다. 내가 아는 한, 내 PHP는 잘 형성되어 있고, 필자는 (필사적으로) chmod'd에 777 디렉토리를 가지고있다. (나는 여기서 무슨 일이 일어나고 있는지 알게 될 것이다. 어떤 충고?

+1

모든 이유를 ""로 변경하십시오. 멋진 따옴표로 알려져 있으며 반드시 코드에 음푹 들어간 부분을 넣을 것입니다. 그렇게하고 다시 시도하십시오. –

+1

오른쪽으로 변경 :'$ fp = fopen ($ filename, "a";);'$ fp = fopen ($ filename, "a");' –

답변

7

"으로 변경하면 그 이유가 있습니다. 500 내부 서버 오류입니다.

멋진 따옴표로 알려져 있으며 코드 실행에 사용하면 안됩니다.

일명 :

  • 스마트 따옴표
  • 곱슬 따옴표

당신은 & 이러한 문자에 대한 당신의 마음에 드는 편집기에서 대체 검색을 할 수 있습니다. 필요한 경우

그리고 일반 인용 부호로 변환하는 스 니펫 :

코드가 존재하는 링크가 지금까지 중단해야 뽑아 :

<?php 
function convert_smart_quotes($string) { 
    //converts smart quotes to normal quotes. 
    $search = array(chr(145), chr(146), chr(147), chr(148), chr(151)); 
    $replace = array("'", "'", '"', '"', '-'); 
    return str_replace($search, $replace, $string); 
} 
?> 

재 작성 : 당신은 캔트

$savestring = " " . "," . $today . "," . " " . "," . $firstname . “,” . $lastname . "," . "I" . $address . "," . $city . "," . $state . "," . $optindealer . "," . $today . "," . $phone . "," . $today . "," . $email . “,” . $optincompany . "," . $today; 

:

<?php 
$firstname = $_POST['firstname']; 
$lastname = $_POST['lastname']; 
$streetaddress = $_POST['streetaddress']; 
$city = $_POST['city']; 
$state = $_POST['state']; 
$phone = $_POST['phone']; 
$email = $_POST['email']; 
//$optindealer = $_POST['optindealer']; 
//$optincompany = $_POST['optincompany']; 

$optindealer = (strtolower($_POST['optindealer']) === 'yes') ? 'Y' : 'N'; 
$optincompany = (strtolower($_POST['optincompany']) === 'yes') ? 'Y' : 'N'; 

$filename = $_POST['filename'] . ".csv"; 

$today = date("YmdHis"); 

    $fp = fopen($filename, "a"); 

    $savestring = " " . "," . $today . "," . " " . "," . $firstname . "," . $lastname . "," . "I" . $address . "," . $city . "," . $state . "," . $optindealer . "," . $today . "," . $phone . "," . $today . "," . $email . "," . $optincompany . "," . $today; 
     echo $savestring; 
    fwrite($fp, $savestring); 
    fclose($fp); 
?> 
2

이 줄에 구문 오류가 을 사용하고 일반 사용 " ...

여기도 있습니다 : $fp = fopen($filename, “a”);