2013-10-28 85 views
0

所以我有以下代碼:HTTP 500錯誤與HTML/PHP的形式

的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內部服務器錯誤(HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.)而我不明白爲什麼。據我所知,我的PHP格式良好,並且我(絕望)已經將目錄修改爲777(當我知道這裏發生了什麼時,我將立即改變它)。有什麼建議?

+1

把你所有的'''''改成'''這就是原因。他們被稱爲花哨的引號,並且肯定會在你的代碼中留下一個凹痕。這樣做,然後再試一次。 –

+1

對,修改:'$ fp = fopen($ filename,「a」);'to'$ 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); 
} 
?> 

重寫:

<?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

你有語法錯誤,在這條線:

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

你不能使用,使用正常的" ...

也在這裏:$fp = fopen($filename, 「a」);