第一个HTML/PHP表单给了我一个500服务器错误

第一个HTML/PHP表单给了我一个500服务器错误,php,html,Php,Html,我的html文件: <html> <head><title>RSS Form</title></head> <body> <form method='post' action='write.php'> <img src='logo.png' align='left' /> <font size='6'>RSS Feed</font><br> The feed th

我的html文件:

<html>
<head><title>RSS Form</title></head>
<body>

<form method='post' action='write.php'>
<img src='logo.png' align='left' />
<font size='6'>RSS Feed</font><br>
The feed that just keeps on giving...<br>

<p>Title:<br>
<input type='text' name='title' size='84' /><br></p>

<p>Article Body:<br>
<textarea rows='20' cols='100' wrap='physical' name='desc'></textarea><br></p>

<input type='submit' value='Post RSS' name='submit'> &nbsp; (Be sure to review the article before pressing this button -- <b>there's no going back</b>)</form><br>

</body>
</html>

RSS表单
RSS源
持续不断的馈送…
标题:

文章正文:

(在按下此按钮之前,请务必查看文章,否则将无法返回)
和Write.php

<html><body>
<?php
$file_name = 'rss.xml';

if !(file_exists($file_name)) {
    initialize_xml($file_name);
}

$rss = fopen($file_name, 'w+') or die('can\'t open file');
remove_tags($rss);
write_content($rss);
close_tags($rss);
finish();

function initialize_xml($name) {
    $rss = fopen($name, 'w') or die('can\'t open file');

    fwrite($rss, "<?xml version=\"1.0\" ?>\n");
    fwrite($rss, "<rss version=\"2.0\">\n");
    fwrite($rss, "<channel>\n");
    fwrite($rss, "<title>---</title>\n");
    fwrite($rss, "<description>This feed will keep users up to date on IT issues that may arise</description>\n");
    fwrite($rss, "<link>---</link>\n");
    fwrite($rss, "<managingEditor>---</managingEditor>\n");
    fwrite($rss, "<webMaster>---</webMaster>\n\n");

    close_tags($rss);
    fclose($rss);
}

function write_content($rss) {
    fwrite($rss, '<item>\n');
    fwrite($rss, '<title>');
    fwrite($rss, $_POST['title']);
    fwrite($rss, '</title>\n');

    fwrite($rss, '<description>');
    fwrite($rss, $_POST['desc']);
    fwrite($rss, '</description>\n');

    fwrite($rss, '<date>');
    $today = getdate();
    $timestamp_format = $today[weekday] + ' ' + $today[month] + ' ' + $today[mday] + ' ' + $today[hours] + ' ' + $today[minutes] + ' ' + $today[seconds];
    fwrite($rss, $timestamp_format);
    fwrite($rss, '</date>');
}

function close_tags($rss) {
    fwrite($rss, '</channel>\n');
    fwrite($rss, '</rss>\n');
    fwrite($rss, '</xml>\n');
}

function remove_tags($rss) {
    // go to end of file
    // remove last 3 lines
}

function finish() {
    echo 'The article '; 
    echo $_POST['title']; 
    echo ' has been added to the feed.\n';
    echo '<a href="index.html">Go Back</a>';
}
?>
</body></html>

这是我第一次接触PHP,所以我很困惑。 当我进入html页面并“提交”我的表单时,我会被重定向到:

HTTP错误500(内部服务器 错误):发生意外情况 安装服务器时遇到错误 试图满足请求


感谢您的帮助

检查服务器的错误日志。应该有更多关于500错误原因的详细信息。您发布的错误消息是“友好的”公共错误消息,设计上说得很少


试着运行一个非常基本的
。如果发生故障,那么您的PHP安装存在一些错误,这会导致Web服务器在调用PHP时发生故障。

检查服务器的错误日志。应该有更多关于500错误原因的详细信息。您发布的错误消息是“友好的”公共错误消息,设计上说得很少


试着运行一个非常基本的
。如果出现这种情况,那么您的PHP安装存在一些错误,导致调用PHP时Web服务器崩溃。

PHP代码的一些更新:

<html><body>
<?php
$file_name = 'rss.xml';

if (!file_exists($file_name)) {
    initialize_xml($file_name);
}

$rss = fopen($file_name, 'w+') or die('can\'t open file');
remove_tags($rss);
write_content($rss);
close_tags($rss);
finish();

function initialize_xml($name) {
    $rss = fopen($name, 'w') or die('can\'t open file');

    fwrite($rss, "<?xml version=\"1.0\" ?>\n");
    fwrite($rss, "<rss version=\"2.0\">\n");
    fwrite($rss, "<channel>\n");
    fwrite($rss, "<title>---</title>\n");
    fwrite($rss, "<description>This feed will keep users up to date on IT issues that may arise</description>\n");
    fwrite($rss, "<link>---</link>\n");
    fwrite($rss, "<managingEditor>---</managingEditor>\n");
    fwrite($rss, "<webMaster>---</webMaster>\n\n");

    close_tags($rss);
    fclose($rss);
}

function write_content($rss) {
    fwrite($rss, "<item>\n");
    fwrite($rss, '<title>');
    fwrite($rss, $_POST['title']);
    fwrite($rss, "</title>\n");

    fwrite($rss, '<description>');
    fwrite($rss, $_POST['desc']);
    fwrite($rss, '</description>\n');

    fwrite($rss, '<date>');
    $today = getdate();
    $timestamp_format = $today['weekday'] . ' ' . $today['month'] . ' ' . $today['mday'] . ' ' . $today['hours'] . ' ' . $today['minutes'] . ' ' . $today['seconds'];
    fwrite($rss, $timestamp_format);
    fwrite($rss, '</date>');
}

function close_tags($rss) {
    fwrite($rss, "</channel>\n");
    fwrite($rss, "</rss>\n");
    fwrite($rss, "</xml>\n");
}

function remove_tags($rss) {
    // go to end of file
    // remove last 3 lines
}

function finish() {
    echo 'The article '; 
    echo $_POST['title']; 
    echo " has been added to the feed.\n";
    echo '<a href="index.html">Go Back</a>';
}
?>
</body></html>

对PHP代码的一些更新:

<html><body>
<?php
$file_name = 'rss.xml';

if (!file_exists($file_name)) {
    initialize_xml($file_name);
}

$rss = fopen($file_name, 'w+') or die('can\'t open file');
remove_tags($rss);
write_content($rss);
close_tags($rss);
finish();

function initialize_xml($name) {
    $rss = fopen($name, 'w') or die('can\'t open file');

    fwrite($rss, "<?xml version=\"1.0\" ?>\n");
    fwrite($rss, "<rss version=\"2.0\">\n");
    fwrite($rss, "<channel>\n");
    fwrite($rss, "<title>---</title>\n");
    fwrite($rss, "<description>This feed will keep users up to date on IT issues that may arise</description>\n");
    fwrite($rss, "<link>---</link>\n");
    fwrite($rss, "<managingEditor>---</managingEditor>\n");
    fwrite($rss, "<webMaster>---</webMaster>\n\n");

    close_tags($rss);
    fclose($rss);
}

function write_content($rss) {
    fwrite($rss, "<item>\n");
    fwrite($rss, '<title>');
    fwrite($rss, $_POST['title']);
    fwrite($rss, "</title>\n");

    fwrite($rss, '<description>');
    fwrite($rss, $_POST['desc']);
    fwrite($rss, '</description>\n');

    fwrite($rss, '<date>');
    $today = getdate();
    $timestamp_format = $today['weekday'] . ' ' . $today['month'] . ' ' . $today['mday'] . ' ' . $today['hours'] . ' ' . $today['minutes'] . ' ' . $today['seconds'];
    fwrite($rss, $timestamp_format);
    fwrite($rss, '</date>');
}

function close_tags($rss) {
    fwrite($rss, "</channel>\n");
    fwrite($rss, "</rss>\n");
    fwrite($rss, "</xml>\n");
}

function remove_tags($rss) {
    // go to end of file
    // remove last 3 lines
}

function finish() {
    echo 'The article '; 
    echo $_POST['title']; 
    echo " has been added to the feed.\n";
    echo '<a href="index.html">Go Back</a>';
}
?>
</body></html>


write.php和write.php不是同一个文件。所有使用撇号(
)的
\n
代码都不起作用。它必须在双引号(
)内。
$today[weekday]
$today[month]
等应为
$today['weekday']
$today['month']
,等等。@Dagon-这是我问题中的一个输入错误。文件名为write.php。@stealthyninja-谢谢,我现在就试试write.php和write.php不是同一个文件。所有使用撇号(
)的代码都不起作用。它必须在双引号(
$今天[工作日]
$today[month]
等,应该是
$today['weekday']
$today['month']
等@Dagon-我的问题是错别字。该文件名为write.php。@Stealthynija-谢谢我现在就试试。谢谢你,我不知道我可以这么容易地查看这些文件。谢谢你,我不知道我可以这么容易地查看这些文件。你的评论加上@Mark B的提示,我可以让它工作了!谢谢你的评论加上@Mark B的提示,我可以让它工作了!谢谢