Issues with php file not rendering at all when in test environment

172
February 02, 2019, at 11:40 AM

Current Test Environment IP: http://18.234.230.152/

I built a basic application that is pulling data from an outside source and storing it in the database from PHP and it is running on the same server as my next step.

My next step is retrieving this information and using it in the HTML output for the dashboard. The code I came up with is below, and it is the most basic query and variable system I can think of, yet when I put it into my test environment, it doesn't work. I would consider myself relatively new to PHP in this application, but from all the research I have done, this seems to be the best route. Any help or suggestions would be appreciated.

I have tried several different styles for making a SQL connection, and even tried storing the variables globally, but had no luck. Also, I have put this code through several formatters to ensure everything is correct, as well as going over by hand after to try and make sure it didn't add something it shouldn't have.

<?php
$servername = "localhost";
$username = "root";
$password = "cfa03183";
$dbname = "wallboard";

// Retrieve Morning Record Data
$conn = new mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT date, team, dollar_amount, car_count FROM morning";
if ($result = $conn->query($sql)) {
    // output data into variables
    $dateb = $result["date"];
    $teamb = $result["team"];
    $damountb = $result["dollar_ammount"];
    $ccountb = $result["car_count"];
}
else {
    echo "Error Retrieving Data/No Data Found in morning table";
}
$conn->close();
// Retrieve Lunch Record Data
$conn = new mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT date, team, dollar_amount, car_count FROM lunch";
if ($result = $conn->query($sql)) {
    // output data into variables
    $datel = $result["date"];
    $teaml = $result["team"];
    $damountl = $result["dollar_ammount"];
    $ccountl = $result["car_count"];
}
else {
    echo "Error Retrieving Data/No Data Found in lunch table";
}
$conn->close();
// Retrieve Lunch Record Data
$conn = new mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT date, team, dollar_amount, car_count FROM dinner";
if ($result = $conn->query($sql)) {
    // output data into variables
    $dated = $result["date"];
    $teamd = $result["team"];
    $damountd = $result["dollar_ammount"];
    $ccountd = $result["car_count"];
}
else {
    echo "Error Retrieving Data/No Data Found in dinner table";
}
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
    <div>
    <div>
    <h1>Drive Thru Records</h1>
    </div>
    <div>
    <h2>Breakfast Record</h2>
        <h3>Team</h3>
        <p><?php
echo $teamb;
?></p>
        <h3>Dollar Amount</h3>
        <p><?php
echo $damountb;
?></p>
        <h3>Car Count</h3>
        <p><?php
echo $ccountb;
?></p>
        <h3>Date</h3>
        <p><?php
echo $dateb;
?></p>
    </div>
        <div>
    <h2>Lunch Record</h2>
        <h3>Team</h3>
        <p><?php
echo $teaml;
?></p>
        <h3>Dollar Amount</h3>
        <p><?php
echo $damountl;
?></p>
        <h3>Car Count</h3>
        <p><?php
echo $ccountl;
?></p>
            <h3>Date</h3>
        <p><?php
echo $datel;
?></p>
    </div>
        <div>
    <h2>Dinner Record</h2>
        <h3>Team</h3>
        <p><?php
echo $teamd;
?></p>
        <h3>Dollar Amount</h3>
        <p>?php echo $damountd; ?></p>
        <h3>Car Count</h3>
        <p><?php
echo $ccountd;
?></p>
            <h3>Date</h3>
        <p><?php
echo $dated;
?></p>
    </div>
    </div>
    </head></html>

The expected result would be that the program pulls the data from the database, assign it to the variables, and then uses echo to place in the correct spot in the HTML.

At this point when I run the code in my test environment, all I get is a page of the code, and no logs or anything to help on screen, I'm stuck, please help!

UPDATE

I went back and look at everything I had downloaded for php, and realized I didn’t download any of the extra components needed. Once I did so, I reloaded the page, and got a 500 ERROR, screenshot below.

Also, I started a new environment on AWS and have gotten the php_info() function to work, but not my program, I still get the 500 Error. And when I check the logs I get this:

[Fri Feb 01 19:21:20.163557 2019] [:error] [pid 14423] [client 73.169.82.233:63540] PHP Fatal error: Uncaught Error: Call to undefined function php_info() in /var/www/html/index.php:1\nStack trace:\n#0 {main}\n thrown in /var/www/html/index.php on line 1

Answer 1

This is the code I used for inserting and rendering data from/into a database, hope this gives you an idea. 'abc.php' is a file that contains passwords etc

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,shrink-to-fit=yes">
<link href="icon.png" rel="icon" type="image/png" />
<link href="css/bootstrap.min.css"   rel="stylesheet">
</head>

<body>
<div class="navbar fixed-top navbar-expand-lg navbar-dark" style="background-color:#000000">
    <div class="container">
    <!--Hipr button starts -->
    <a class="navbar-brand" href="web.html"><button type="button" class="btn btn-success">Home</button></a>
    <!-- Hipr button ends -->
    <!-- target button starts(incomplete) -->
    <!--profile  -->
        <a class="navbar-brand" href="third.html" style="color:#FFFAFA" title="Hipr wants to connect with you">Sign up</a>
    <!--profile  -->
    <!-- Suggest div starts -->
        <a title="Thinktank" class="navbar-brand" href="second.php" style="color:#FFFAFA">Suggest</a>
    <!-- Suggest div ends -->
    </div>
    </div>
        <br><br><br>
        <marquee>The reward of deeds depends upon the intentions.</marquee>
        <br>
          <!--topic here-->
          <h2 id="ve"></h2>
<br><br>
<form  class="container" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
Unique heading<br> <input type="text "name="hea"  placeholder=""  required /><br><br>
Comments<br><textarea name="educ"  placeholder="Write about the topic here" rows="5" cols="40" required></textarea>
<br><input type="submit" name="s" value="Share!!!"/> <br><hr>
</form>
 <!--Footer-->
<div class="navbar fixed-bottom" style="background-color:#00FF00">
<div class="container">
<p class="navbar-brand" style="font-size:70%">footer</p>
<a class="navbar-brand" href="web.html#about"><button type="button" class="btn btn-dark btn-md">About</button></a>
</div>
</div>

<?php
error_reporting(0);
require('abc.php');

//ASSIGNING TO VARIABLES
$edu = $_REQUEST['educ'];
$head =$_REQUEST['hea'];
//insert values in table
if(isset($edu) && !empty($edu) && isset($_POST['s'])){
//reconnect first
// Create connection
$con = new mysqli($servername, $username, $password,$dbname);
//echo "connected";
$ins = "INSERT INTO self (head,comments)
VALUES ('$head','$edu')";
if ($con->query($ins)) {
    echo "<div class='container'><i>".htmlspecialchars($head)."</i></div>";
    echo "<div class='container'>".htmlspecialchars($edu)."</div><hr>";
} else {
    //echo "<br>Error: " . $sql . "<br>" . $conn->error;
}
//closing connection
$con->close();
}
else
{
    echo "";
}

// Create connection
$conn = new mysqli($servername, $username, $password,$dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
//echo "Connected successfully";
//Loading previous data
$sel = "SELECT * FROM self";
$res = $conn->query($sel);
if ($res->num_rows > 0) {
    // output data of each row
    while($row = $res->fetch_assoc()) {
        echo "<div class='container'><i>".htmlspecialchars($row["head"])."</i></div>";
        echo "<div class='container'> " . htmlspecialchars($row["comments"])."</div><hr>";
    }
} else {
    echo "No definitions yet";
}
$conn->close();
?>
<!--img-->
<center><img src="1.png" class="container"/><center>

<script>
function view(comment) {
    this.comment = comment;
}
var a = new view("<hr><div class='container'>Self(Be precise)</div><hr>");
document.getElementById("ve").innerHTML = a.comment;
</script>
</body>
</html>
Rent Charter Buses Company
READ ALSO
Laravel AdminLTE - How to call method and use its data in view

Laravel AdminLTE - How to call method and use its data in view

I am using Laravel AdminLTE and I have it all configured, there is just one part I do not understandI made my route like so:

181
Is there some way to manage multiple domains content and layout through one single Laravel project?

Is there some way to manage multiple domains content and layout through one single Laravel project?

I'm setting up a Laravel project and I want to manage content and layout of different domains through this projectI need to implement in a way how shopify works

157
Why dynamically created image share to facebook using og:image tag in php is not working?

Why dynamically created image share to facebook using og:image tag in php is not working?

I have a requirement as below: My website generates image on the fly when user performs an actionI am storing generated image on the server itself

129