简体   繁体   English

PHP代码无法正常工作,出现服务器错误500

[英]PHP code not working getting server error 500

UPDATE: Thank you all for the late night help. 更新:谢谢大家的深夜帮助。 I Have updated the code below with the changes that I have made. 我已经用所做的更改更新了下面的代码。 If a line is commented it is something I tried and it didn't work, what isn't commented out right now was my last attempt. 如果某行被注释,这是我尝试过的方法,但是没有用,现在没有注释的是我最后一次尝试。 I am still not able to get my page to load. 我仍然无法加载我的页面。 Again Thank You!. 再次谢谢你!。

Website location: www.encapdio.com/pyscraper.php I am a systems guy taking a shot at programming and decided to put a website together to learn php. 网站位置:www.encapdio.com/pyscraper.php我是一名从事编程工作的系统人员,决定组建一个网站来学习php。 My code if causing the page to error 500 and even with my php.ini file showing errors it seems its just breaks. 我的代码如果导致页面错误500,即使我的php.ini文件显示错误,它似乎也会中断。 I can't find any errors in my code, but I most likely need a fresh pair of eyes. 我在代码中找不到任何错误,但是我很可能需要一双崭新的眼睛。 This is what it should do. 这就是它应该做的。

The purpose of this page is to grab line per line stock ticker symbols. 该页面的目的是抓取每行股票行情自动收录器符号。 Once you hit submit my code should check the textarea if its empty. 一旦您点击提交,我的代码应检查textarea是否为空。 If it isn't empty then take the $content in to an array, add $linebreak to the end of each array item and account for \\r type line breaks, Next write each entry line by line in to the file. 如果不为空,则将$ content放入数组,在每个数组项的末尾添加$ linebreak,并说明\\ r类型的换行符,然后逐行将每个条目写入文件中。 If it is empty to echo out that no tickers were entered. 如果为空,则回显未输入报价器。

Then there if all was successful and the status = results you get to see the ticker symbols next to their stock price. 然后,如果一切成功,并且状态=结果,您将看到其股票价格旁边的股票代码。 I have a fully tested python script checking the ticker_inputs.txt file that will execute my webcrawler/scraper/ticker_inputs.txt updater. 我有一个经过全面测试的python脚本,用于检查ticker_inputs.txt文件,该文件将执行我的webcrawler / scraper / ticker_inputs.txt更新程序。

It is the php that I cannot get to update the ticker_input.txt file or even show the php and html on the same page without that server error 500. 这是我无法更新ticker_input.txt文件或什至在没有该服务器错误500的情况下在同一页面上显示php和html的php。

Example Code: 示例代码:

<?php
include("inc/header.php");
include("inc/nav.php");

#if (isset ($_POST[$text_name])) && $_POST['text_name'] != "") {
if (!empty($_POST['textfile'])) {
    $content = isset($_POST['textfile'])?$_POST['textfile']:"";
    $linebreak = explode("\n", str_replace("\r", "", $content));
  $tick_wfile = fopen("ticker_input.txt", "w") or die("Unable to open file!");
    fwrite($tick_wfile,$linebreak);
    fclose($tick_wfile);
   if (empty($_POST['textfile'])) {
   echo "No Tickers Were Entered!";
  }
header("Location: pyscraper.php?status=results");
exit;
}
include("inc/header.php");
include("inc/nav.php"); ?>

<div class="container" align="center">
    <div class="page-header">
          <br><h1>Web Scraper<small> built with python</small></h1>
    <?php if (isset($_GET["status"]) && $_GET["status"] == "results") {
         $tick_rfile = fopen("ticker_input.txt","r") or die("Unable to open file after writting to it!");
        echo fread($tick_rfile,filesize("ticker_input.txt"));
        fclose($tick_rfile);
} else { ?>
    <form name="savefile" method="post" action="">
        <fieldset class="form-group">
        <label for="tickerlist">Enter Tickers <small>(one per line)</small></label>
        <textarea name="textfile" class="form-control" rows="5"></textarea>
        </fieldset>
        <button type="submit" name="submit_file" value="Save File" class="btn btn-primary">Submit</button>
    </form>
    <?php } ?>
    </div>
</div>
<?php include("inc/footer.php"); ?>

Try changing: 尝试更改:

header("location:pyscraper.php?status=results");

To

header("Location: pyscraper.php?status=results");
exit;

Basically, without the exit; 基本上没有exit; the rest of the PHP is still executed. 其余的PHP仍将执行。 Also HTTP headers are case sensitive . HTTP标头也区分大小写

If this does not work, I'll remove the answer. 如果这不起作用,我将删除答案。 Posting as a comment would have been harder to follow. 发表评论将更加困难。

One closing parenthesis is missing in this line 此行中缺少一个右括号

$linebreak = explode("\\n", str_replace("\\r", "", $content);

Check your code 检查你的代码

An open paranthesis is missing on fourth line after isset. isset之后的第四行缺少开放式括号。

Also you can't check using isset on a function call.Try using empty() instead. 另外,您不能在函数调用中使用isset进行检查,而是尝试使用empty()。 $_POST['textfile'] is always set but can be empty $ _POST ['textfile']始终设置,但可以为空

check this link for more 检查此链接了解更多

You are missing the isset brackets here if (isset $_POST[$text_name]) . if (isset $_POST[$text_name])这里缺少isset括号。 Try this instead to check if its empty and if it's set if(isset($_POST[$text_name]) && $_POST['text_name'] != "") 尝试使用此方法来检查其是否为空以及是否已设置if(isset($_POST[$text_name]) && $_POST['text_name'] != "")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM