douyu9012 2017-04-20 14:38
浏览 140

无法加载资源:加载php脚本时,服务器响应状态为500(内部服务器错误)

i've removed my credentials now so here is my issue again, i get a 500 internal server error whenever i try to run a php script on my website, the permissions are set to 644, so that is not the issue.

here is the html code i'm running:

<html>
<head>
<title></title>
</head>
<body>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
  <div class = "container">
    <nav class = "navbar navbar-inverse">
      <div class = "container-fluid">
        <div class = "navbar-header">
          <a class = "navbar-brand" href = "index.html">YardSaleMapper.com</a>
        </div>
        <ul class = "nav navbar-nav">
          <li><a href = "index.html">Go Home</a></li>
          <li class = "active"><a href = "viewSales.php">View Sales</a></li>
          <li><a href = "addSale.html">Publish your Sale</a></li>
        </ul>
      </div>
    </nav>
    <h3>Enter Starting Point</h3>
    <hr/>
    <form method = "post" id = "myForm">
      <div class = "col-md-2">
        <div class = "form-group">
          Street:
          <input class = "form-control" type = "text" name = "start_street" ng-model = "ss" required/>
        </div>
      </div>
      <div class = "col-md-2">
        <div class = "form-group">
          City:
          <input class = "form-control" type = "text" name = "start_city" ng-model = "ss" required/>
        </div>
      </div>
      <div class = "col-md-2">
        <div class = "form-group">
          State (EX: PA):
          <input class = "form-control" type = "text" name = "start_state" ng-model = "ss" maxlength="2" required/>
        </div>
      </div>
      <div class = "col-md-2">
        <div class = "form-group">
          ZIP
          <input class = "form-control" type = "text" name = "start_zip" ng-model = "ss" maxlength="5" required/>
        </div>
      </div>
      <div class = "col-md-2">
        <div class = "form-group">
          Within <select type = "text" name = "distance" required  class = "form-control">
            <option value = 5>5</option>
            <option value = 10>10</option>
            <option value = 15>15</option>
            <option value = 20>20</option>
            <option value = 25>25</option>
          </select>
          Miles
        </div>
      </div>
      <div class = "col-md-2">
        <div class = "form-group">
          &nbsp
          <a class ="btn btn-primary btn-block" id = "submit" name = "submit">Submit</a>
        </div>
      </div>
    </form>
  </div>

  <script id = "source" language = "javascript" type = "text/javascript">
  $(function() {
    $('#submit').on('click', function() {
      $.ajax({
        url: 'getSales.php',
        method: 'post',
        data: $("#myForm").serialize(),
        dataType: 'json',
        success: function(data) {
          console.log(data);
        }
      })
    })
  });
  </script>

</body>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>


</html>

and here is the php code i'm running

<?php
  $servername = "....";
  $username = "....";
  $password = "....";
  $dbname = "....";

  $data = array();

  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);
  // Check connection
  if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);

  }

  $street = $_POST["start_street"];
  $city = $_POST["start_city"];
  $state = $_POST["start_state"];
  $zip = $_POST["start_zip"];
  $dist = $_POST["distance"];

  $address = $street . ", " . $city . ", " . $state . ", " . $zip;

  $geo = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&sensor=false');

  // Convert the JSON to an array
  $geo = json_decode($geo, true);

  if ($geo['status'] == 'OK') {
    // Get Lat & Long
    $lat = $geo['results'][0]['geometry']['location']['lat'];
    $long = $geo['results'][0]['geometry']['location']['lng'];

  }

  $sql = "SELECT street, city, state, zip, county, sdate, edate,
  stime, etime, description, 69 * vincenty($lat, $long, lat, long) AS distance from
  sjodsijfoisjdf237423947 where 69 * vincenty($lat, $long, lat, long) < $dist";

  $result = $conn->query($sql);

  while($row = $result->fetch_assoc()) {
    $data[] = $row;
    echo($row);
  }

  echo json_encode($data);

?>

the thing that is confusing to me is i've already run the code on a localhost (xampp) and everything worked 100% fine, now i've transfered the code to ecowebhosting and it is not working. also, when i visit the url on the webserver: view-source:http://yardsalessepa-com.stackstaging.com/getSales.php you can see that there is no source code there, however i've provided the source code i've written above, so i think that may be the main issue.

  • 写回答

2条回答 默认 最新

  • doutuan4361 2017-04-20 14:45
    关注

    it looks like the page doesn't echo the data, are you sure that your $data is not empty.

    you can see this by using var_dump($data);

    documentation http://php.net/manual/en/function.var-dump.php

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘