Solution 1 :

Your POST request produces 500 error.

Check the error_reporting, display_errors and display_startup_errors settings in your php.ini file. They should be set to E_ALL and “On” respectively or change through code as follows. This will display the actual error produced. That will give insight on what goes wrong.

ini_set('display_errors', 'On');

Solution 2 :

Add the following on the top of your code.

ini_set('display_errors', 1); 
ini_set('display_startup_errors', 1); 

Always, use the try-catch exception method.
Exceptions are used to change the normal flow of a script if a specified error occurs.

Moreover, you can always check apache2 error logs from where you will get error logs based on timestamps.

Problem :

The user submits the response to the poll it’s not displaying the results from the database. This is the website I’m unsure what’s wrong and why nothing is showing? I didn’t think I needed to add the HOST USER PASS BASE but I included it to see if it would work, still won’t.

  • After submitting the answer it’s just blank, nothing at all is showing. Below is the code. It should show on the same page just reload it.

*** Update Thank you to Ken Lee, I made a rookie mistake of not including the ‘includes’ file when uploading to my server. I fixed that, and now it’s showing the “results” page but not actually displaying the results. I want it to show the different options and the results with the % from highest to lowest. This database isn’t supposed to be safe as it’s a project for college (first PHP/SQL class) and we aren’t yet making it all secure.

    include 'includes/dp.php';

    //Function to create the page
    function createPage(){
            echo createQuestionare();

        //If all variables are set, add to database and display results
            addToDataBase($_POST['food'], 'poll');
    define("HOST", "****");
    define("USER", "****");
    define("PASS", "****");
    define("BASE", "****");

    $conn = mysqli_connect(HOST, USER, PASS, BASE);

    //Create questionare
    function createQuestionare(){
        $content = "";
        $content .= "<div class='main'>";
        $content .= "<h1 class='title'>Food Poll</h1>";
        $content .= "<form action='.' method='post'>";

        $content .= createQuestion();
        //Close form
        $content .= "<input type='submit'>";
        $content .= "</form>";
        $content .= "</div>";

        return $content;

    //Create question
    function createQuestion(){
        $arr = ["Pizza", "Burger", "Salad", "Pasta"];

        //Question to ask
        $content = "";
        $content .= "<h1 class='question-text'>Which food is most satisfying?</h1>";

        //Create radio button and label for each possible question
        foreach($arr as $subject){
            $content .= "<input type='radio' id='$subject' value='$subject' name='food'>";
            $content .= "<label for='$subject'>$subject</label><br>";

        return $content;

    //Function adds data to DB 
    function addToDataBase($data, $DBName){
        //Edit string to be lowercase
        $data = strtolower($data);
        $conn = connectToDB();

        //Check database for primary key of answer 
        $sql = "SELECT * FROM $DBName WHERE name='$data';";
        $results = mysqli_query($conn, $sql);

        if(mysqli_num_rows($results) != 0){
            $key = mysqli_fetch_array($results, MYSQLI_ASSOC)['id'];

        //Increment vote number and insert value
        $sql = "UPDATE $DBName SET votes = votes + 1 WHERE id=$key;";
        mysqli_query($conn, $sql);

    //Function to display results
    function displayResults(){

        $arr = ['poll'];

        //Create results content
        $content = '';
        $content = '<div class="main">';
        $content .= "<h1 class='title'>Thank You!</h1>";
        foreach($arr as $DBName){
            $content .= '<div class="result-container">';
            $content .= getResults($DBName);
            $content .= '</div>';
        $content .= '</div>';
        echo $content;

    //Function will display results highest to lowest
    function getResults($DBName){
        $conn = connectToDB();

        $sql = "SELECT * FROM $DBName;";
        $results = mysqli_query($conn, $sql);

        $sql = "SELECT SUM(votes) as total FROM $DBName;";
        $total = mysqli_query($conn,$sql);
        $total = mysqli_fetch_assoc($total)['total'];

        //Create an associate array with percentage and name
        $sortedArray = array();
        while($row = mysqli_fetch_array($results, MYSQLI_ASSOC)){
            $name = $row['name'];
            $percentage = round($row['votes']/$total * 100);
            $sortedArray[$name] = $percentage; 

        //Sort by percentage
        $content = '';
        $content = '<h1 class="result-text">Results</h1>';

        //Display results
        foreach($sortedArray as $name => $percentage  ){
            $content .= "<h2>". ucwords($name) ." has $percentage% of the votes</h2>";

        return $content;
<!DOCTYPE html>

<html lang="en" >
    <meta charset="utf-8" />
    <link rel="stylesheet" href="css/style.css">


Comment posted by Breezer

You have an error somewhere add

Comment posted by Anuj Shrestha

IMPORTANT: do not share your database credentials here even if it is just a staging server.

Comment posted by Ken Lee

Are you sure

Comment posted by how?

1) Check your PHP Error logs (

Comment posted by READ HERE

And you need to stop SQL injection on your script, what happens if one of the HTML inputs is

Comment posted by Martin

It would be better to educate the OP about how to display errors in their error log file rather than having errors on show to the general public on the page.

Comment posted by Martin

re PHP Errors; It would be better to educate the OP about how to display errors in the error log file rather than having errors on show to the general public upon page load.

Comment posted by Shashank Shah

Agreed @Martin its always good to monitor the apache error log files.