使用html/php表单的HTTP 500错误

gfp*_*ste 0 php forms

所以我有以下代码:

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>
Run Code Online (Sandbox Code Playgroud)

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); 



?> 
Run Code Online (Sandbox Code Playgroud)

每当我尝试提交表单时,我都会收到500内部服务器错误(HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.)并且我无法弄清楚原因.据我所知,我的PHP形式很好,我(绝望)已经将目录chmod到777(一旦我弄清楚这里发生了什么,我就会改变).有什么建议?

Fun*_*ner 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);
}
?>
Run Code Online (Sandbox Code Playgroud)

改写:

<?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); 
?>
Run Code Online (Sandbox Code Playgroud)