0

The following code pulls data from a database (I am using MAMP and phpmyadmin) and then displays the code in an HTML page. I tested the SQL queries in phpmyadmin and they work there. The issue is that I am getting a 500 Error when I try to display the page with MAMP. The php page is in the htdocs folder within the MAMP folder. The page has displayed previously when my PHP code was more simple, but now it doesn't, so I am guessing the error is being caused by syntactical issues. Can someone please help?

Here is the code:

<!DOCTYPE html>
   <html>
      <head>
         <title>Job Applicants Report</title>
         <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.9.1/build/cssreset/cssreset-min.css">
         <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.9.1/build/cssbase/cssbase-min.css">
         <style type="text/css">
           #page {
             width: 1200px;
             margin: 30px auto;
           }
           .job-applicants {
             width: 100%;
           }
           .job-name {
             text-align: center;
           }
           .applicant-name {
             width: 150px;
           }
         </style>
      </head>
      <body>

  <?php

    $conn = new mysqli("localhost", "localhost1", "localhost", "fashionphile");

    if (mysqli_connect_errno()) {
        printf("Connection failed: %s\n", mysqli_connect_error());
        exit();
    }

    $getinfo_job = "SELECT name FROM jobs";
    $job_result = $conn->query($getinfo_job);
    $job_result_array = mysqli_fetch_array($job_result, MYSQLI_NUM);

    $getinfo_applicant_webdeveloper = 
      "SELECT j.id, a.name, a.email, a.website, a.cover_letter
       FROM applicants a
       JOIN jobs j ON a.job_id = j.id
       WHERE j.id = 1";
    $result = $conn->query($getinfo_applicant_webdeveloper);
    $application_webdeveloper_arr = $result->fetch_assoc();

    $getinfo_applicant_designer = 
      "SELECT j.id, a.name, a.email, a.website, a.cover_letter
       FROM applicants a
       JOIN jobs j ON a.job_id = j.id
       WHERE j.id = 2";
    $result = $conn->query($getinfo_applicant_designer);
    $application_designer_arr = $result->fetch_assoc();

    $skills_arr_rowcount_perapplicant = "SELECT COUNT(*) FROM skills s JOIN applicants a ON a.id = s.applicant_id WHERE s.applicant_id = a.id";

    $skills_toprowname = "SELECT s.name FROM skills s JOIN applicants a ON a.id = s.applicant_id";
    $skills_toprowname_result = $conn->query($skills_toprowname);
    $skillslist_array = mysqli_fetch_array($skills_toprowname_result, MYSQLI_NUM);

    $skills_distinct_count = "SELECT COUNT(DISTINCT name) FROM skills";

    $applicants_distinct_count = "SELECT COUNT(DISTINCT name) FROM applicants";

    if ($getinfo_applicant->num_rows > 0) {
      echo '<div id="page">
      <table class="job-applicants">
        <thead>
          <tr>
            <th>Job</th>
            <th>Applicant Name</th>
            <th>Email Address</th>
            <th>Website</th>
            <th>Skills</th>
            <th>Cover Letter Paragraph</th>
          </tr>
        </thead>

        <tbody>
            <!-- Web Developer -->
            <tr>
              <td rowspan="10" class="job-name">Web Developer</td>'

      while ($application_webdeveloper_arr[]) {
        echo '<td rowspan="' . $skills_arr_rowcount_perapplicant . '" class="applicant-name">' . $application_webdeveloper_arr['name'] . '</td>
              <td rowspan="' . $skills_arr_rowcount_perapplicant . '"><a href="mailto:kaitlin@lesch.co.uk">' . $application_webdeveloper_arr['email'] . '</a></td>
              <td rowspan="' . $skills_arr_rowcount_perapplicant . '"><a href="http://berge.biz/">' . $application_arr['website'] . '</a></td>
              <td>' . $skillslist_array[0] . '</td>
              <td rowspan="' . $skills_arr_rowcount_perapplicant . '">' . $application_arr['cover_letter'] . '</td>
            </tr>'

                  if (count($skillslist_array) > 1) {
                    for ($i = 1; $count = count($skillslist_array) - 1; $i <= $count; $i++) {
                      echo  . '<tr>
                              <td>' . $skillslist_array[i] . '</td>
                            </tr>' . ;
                    }
                  }

              '<tr>'
      }
      echo '<!-- /Web Developer --><!-- Designer -->

            <td rowspan="12" class="job-name">Designer</td>';

      while ($application_designer_arr[]) {
        echo '<td rowspan="' . $skills_arr_rowcount_perapplicant . '" class="applicant-name">' . $application_designer_arr['name'] . '</td>
              <td rowspan="' . $skills_arr_rowcount_perapplicant . '"><a href="mailto:kaitlin@lesch.co.uk">' . $application_designer_arr['email'] . '</a></td>
              <td rowspan="' . $skills_arr_rowcount_perapplicant . '"><a href="http://berge.biz/">' . $application_designer_arr['website'] . '</a></td>
              <td>' . $skillslist_array[0] . '</td>
              <td rowspan="' . $skills_arr_rowcount_perapplicant . '">' . $application_designer_arr['cover_letter'] . '</td>
            </tr>'

                  if (count($skillslist_array) > 1) {
                    for ($i = 1; $count = count($skillslist_array) - 1; $i <= $count; $i++) {
                      echo  . '<tr>
                              <td>' . $skillslist_array[i] . '</td>
                            </tr>' . ;
                    }
                  }

              '<tr>'
      }

      echo '<!-- /Designer -->
            </tbody>
            <tfooter>
              <tr>
                <td colspan="6">' . $applicants_distinct_count . 'Applicants, ' . $skills_distinct_count . 'Unique Skills</td>
              </tr>
            </tfooter>
          </table>
        </div>';

    }

    $conn->close();

  ?>
  </body>
</html>
azro
  • 53,056
  • 7
  • 34
  • 70
  • Could you please add PHP error logs outputs? – max Aug 01 '17 at 18:09
  • What is this `while ($application_webdeveloper_arr[]) {` supposed to do? – GrumpyCrouton Aug 01 '17 at 18:11
  • A 500 error means that a server error occurred. This is most likely an error in your PHP-code. To see the _actual_ error message, check your servers error log. You can also change how PHP displays errors and tell it to show all errors directly on the screen (this is not something you want in production though, since it can show sensitive data, but during development, you should). Here's how to show all errors and warnings: https://stackoverflow.com/questions/5438060/showing-all-errors-and-warnings – M. Eriksson Aug 01 '17 at 18:12
  • I am fairly new to phpmyadmin - where can I find the error log outputs? – user6620970 Aug 01 '17 at 18:13
  • Your code have nothing to do with PHPMyAdmin (which simply is a web app to manage mysql databases). For finding error log in Mamp, check if this can help you: https://stackoverflow.com/questions/8641383/how-can-i-get-mamp-to-tell-me-what-went-wrong-with-php-code – M. Eriksson Aug 01 '17 at 18:13
  • Ok, I found the error log. It looks like this is the error: [01-Aug-2017 19:47:12 Europe/Berlin] PHP Parse error: syntax error, unexpected 'while' (T_WHILE), expecting ',' or ';'. The while loop condition is just to specify as long as there is content in the the array, run the code in the loop. I am also fairly new to PHP - what am I missing in the conditions of the two while loops? I just want the loops run as long as there is another row of data in the array. – user6620970 Aug 01 '17 at 18:16
  • To start with: `' . ;` is wrong. Remove the trailing `.`'s – M. Eriksson Aug 01 '17 at 18:16
  • `Web Developer'` is missing a `;`. – M. Eriksson Aug 01 '17 at 18:17
  • You have a lot of syntax errors. You know where to find the error log (and you should turn on display_errors). Go through all errors and solve them. – M. Eriksson Aug 01 '17 at 18:18
  • The only specific error in the log is the one I added above. – user6620970 Aug 01 '17 at 18:19
  • When you fix that one, you will most likely get another one. Anyway, you got a solution to that error (the missing `;` in the echo before the `while`). You got missing `;`'s after many echo's. Semi colons can not be omitted in PHP, unless you only have a single statement inside a code block, like : ``. If you have more than one, you _must_ have a semi colon after each statement. – M. Eriksson Aug 01 '17 at 18:28
  • @user6620970 you also have `''` in the middle of nowhere and the end of both loops, this is not valid. It needs an `echo` in front of it and a semicolon at the end. My honest advice to you would be to completely rewrite the code creating the table. I tried cleaning it up and had very little luck, it doesn't make much sense. – GrumpyCrouton Aug 01 '17 at 18:31
  • You got way too many errors for us to be able to sit and point them all out for you. Basically, make sure your code has the correct syntax. – M. Eriksson Aug 01 '17 at 18:32
  • Isn't making sure the syntax is correct the point of asking the question? – user6620970 Aug 01 '17 at 18:41

0 Answers0