PHP distributing empty sheets (possibly for website configuration)

Hey everyone! I've been struggling to set up a profile page on my website for the past week. Whenever I try to include PHP code or echoes in the content pages, I either get blank pages or encounter a 500 server error.

My website is structured with a static page for the logo, navbar, and footer, with content included using an include line. (I hope that makes sense).

Whenever I add any PHP code into the content pages, it triggers a 500 server error or turns the pages completely white.

Is there a specific way to display SQL content or any PHP with this setup? If anyone knows of any tutorials or could offer some assistance, that would be greatly appreciated. Any help provided will be credited on the website's Credits page.

Here is the code snippet for the static page:

<?php require '../connection/conn.php'; ?>
<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title><?php echo $title; ?></title>
        <link rel="stylesheet" type="text/css" href="../css/Master.css" />
        <link rel="stylesheet" type="text/css" href="../css/Menu.css" />
        <link rel="stylesheet" type="text/css" href="../css/AboutImages.css" />
        <link rel="stylesheet" type="text/css" href="../css/Form.css" />
    </head>
    <body>
        <div class="container">
        <div class="header">
        <div id="logindata"></div>
        </div>
        <div class="menu">
            <nav>
               <ul class="cssmenu">
                  <li><a href="index.php">Home</a></li>
                  <li><a href="About.php">About Us</a></li>
                  <li><a href="Videos.php">Videos</a></li>
                  <li><a href="Contact.php">Contact Us</a></li>
                  <li><a href="Forum.php">Forum</a></li>
                  <li><a href="#"></a></li>
                  <li><a href="Account.php">My Account</a></li>
                  <li><a href="../connection/logoutscript.php">Logout</a></li>

                </ul>
            </nav>
        </div>
        <div class="content">
        <?php echo $content;?>

        </div>
        <div class="footer">
            <p>All Rights Reserved, LPGamers.com, Created And Built by Robert Prince &amp; Amber Milton-White</p> <a href="#">Credits Page</a>
        </div>
 </div>
    </body>
</html>

And here is the content page:

<?php

$title = 'LPGamers -- Personal Account';

$content = '
<div id="formbox">
    <form action="" method="GET">
        <p>Search for your friends here!</p>
        <input type="text" class="tfield">
        <input type="submit" class="button">
    </form>
</div>
<div class="ppicture">
    <img src="" />
</div>
<div class="pd">
    </br>
    <p class="pdp">
    Account ID: # $userid
    </p>
    </br>
    <p class="pdp">
    Name: 
    </p>
    </br>
    <p class="pdp">
    Age: 
    </p>
    </br>
    <p class="pdp">
    Your Email: 
    </p>
    </br>
    <p class="pdp">
    Your Bio: 
    </p>
</div>
';

include ("Site_View.php");

?>

If anyone can provide further assistance, thank you in advance!

Answer №1

Modified the response to address some missing information from the original post.

  1. Avoid embedding the form within PHP code, as it is unnecessary. It's more suitable to display the result there.
  2. If you need to fetch data from a SQL database in PHP, follow these steps: Precondition: Configure php.ini to utilize the required database extension, e.g., extension=php_sqlsrv_56_nts.dll

Establish a connection with the database

$serverName = "myserver";
$usr="mySQLuser";
$pwd="mySQLpass";
$db="mydatabase";
$connectionInfo = array("UID" => $usr, "PWD" => $pwd, "Database" => $db);
$conn = sqlsrv_connect($serverName, $connectionInfo);
if( !$conn ) {
    die( print_r( sqlsrv_errors(), true));
}

Utilize the SQL connection to retrieve data.

$sql = "Select name from Users where users.name = " . $myparam;

note: The example provided above is susceptible to SQL injection. However, it serves as a starting point for coding, and security measures can be added later once you gain familiarity with it. Ensure to assign a value to $myparam beforehand.

Next:

$stmt = sqlsrv_query($conn, $sql);
sqlsrv_next_result($stmt);
sqlsrv_fetch($stmt);
if( $stmt === false) {
  die( print_r( sqlsrv_errors(), true) );
}

You can now use the retrieved data as needed, for instance:

<?php
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
  $returnedName = $row['name'];
  echo $returnedName;
}
?>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Dynamically Loading CSS files in a JQuery plugin using a Conditional Test

I'm trying to figure out the optimal way to dynamically load certain files based on specific conditions. Currently, I am loading three CSS files and two javascript files like this: <link href="core.min.css" rel="stylesheet" type="text/css"> & ...

Is it recommended to place the styles created by material-ui for child components after the styles generated for the parent component?

Utilizing material-ui, which utilizes JSS for styling a website. I have a component named Layout that applies margin to all its children (using the all children selector & > * in its style). This functionality works, but I would also like the child ...

When the CSS grid is equipped with a sticky left column, it will horizontally scroll if the grid's width exceeds 100% of its containing element

I am facing an issue with a CSS grid layout that has sticky left and right columns as shown below: .grid { display: grid; grid-template-columns: repeat(10, 200px); } .grid > div { border: 1px solid black; background-color: white; } .sticky- ...

When using Vue.js, binding may not function properly if it is updated using jQuery

Link to JsFiddle Below is the HTML code: <div id="testVue"> <input id="test" v-model="testModel"/> <button @click="clickMe()">Click me</button> <button @click="showValue()">Show value</button> </div& ...

Modifying a div element upon the successful completion of an ajax/json request

Currently, I have a form on my webpage for creating a new album. Alongside this form, there is also a delete album form. After successfully creating an album, I want to automatically update the checkbox list in the delete album form with the details of the ...

How can I access the next_post_url() and next_post_title() functions in Wordpress?

Here is the HTML code I want to implement with Wordpress's next_post_link() and previous_post_link(). The URL and title are enclosed in HTML tags, including single_cat_title(). This complex HTML structure makes it difficult to use next_post_link() and ...

What is the resemblance in WordPress templates all about?

<?php foreach ( $incomplete_custom_resources as $resource ) { echo '<tr>'; echo '<td>' . $resource->post_title . '</td>'; } ?> How can this code be converted to pure PHP and ...

What is the best way to retrieve user groups in Django?

My goal is to investigate the user groups associated with a user in Django. However, when I check the console, I encounter the message: Uncaught ReferenceError: user is not defined at 6/:643:33 The purpose of the function is to redirect the user based ...

Generate a new JSON reply using the current response

I received a JSON response that contains values for week 1, week 2, week 3, and week 4 under the 'week' key, along with counts based on categories (meetingHash) and weeks. I attempted to merge this data using the .reduce method but without succes ...

Nested divs with inline formatting

On my HTML page, I have the following structure: <div id="frst"> FIRST </div> <div id="top"> <div id="mid"> <div id="bottom"> <ul class="menu"> <li>A</li> ...

Make sure to load the gif image before any other images are loaded from the css

Hey there, I'm attempting to display a GIF image before the actual image loads. I found a great example to accomplish this: Example: Java Script function loadimage(imgsrc, change){ var loadimage = new Image(); loadimage.onload = changesrc(imgsrc, c ...

Leveraging node.js and express for incorporating custom stylesheets and scripts

I recently designed a webpage with the following elements at the beginning: <link href="./css/font-awesome.min.css" rel="stylesheet"> <link href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600" rel="stylesheet ...

"Ensure that the data in the div is being updated accurately via AJAX in ASP.NET MVC

I'm currently using a div element to display data on page load through AJAX calls. $(document).ready(function () { email_update(); }); function email_update() { $.ajax({ url: '@Url.Action("EmailsList", "Questions")', ...

Tips for preventing Google from indexing the URL of the Openshift Wordpress app

My Wordpress site is currently hosted on free Openshift by RedHat. After adding a custom domain, everything seems to be working fine. The issue I'm facing is that both URLs - www.namanboard.com (custom) and nb-namanwp.rhcloud.com (Openshift app) are ...

Activate a CSS class on click using JavaScript

Having a bit of trouble as a beginner with this. Any help would be much appreciated. This is the code in question: HTML: <div class='zone11'> <div class='book11'> <div class='cover11'></d ...

Tips for Customizing the Width of Your Material UI Alert Bar

At the moment, I have refrained from using any additional styling or .css files on my webpage. The width of the Alert element currently spans across the entire page. Despite my attempts to specify the width in the code snippet below, no noticeable change ...

Laravel 8 - sweet alert functions properly, however, the ajax functionality is not functioning as expected

As a newcomer to Ajax, I am facing an issue with deleting records from the database using Sweet Alert2. Although my swal is working fine, the ajax function seems to be malfunctioning. Can anyone point out where the problem might be and suggest a solution? ...

I encountered a problem while trying to incorporate the solution that prompts another button click event

Interesting topic: JQuery / JavaScript - triggering button click event from another button <input type="submit" name="savebutton" id="uniqueOne" /> <input type="submit" name="savebutton" id="uniqueTwo" /> I have implemented a feature on my si ...

Is the default animation duration of Compass being ignored?

After recently updating to Compass version 1.0.16, I started setting up basic usage of the new animation features. However, I encountered an issue where setting default values for different animation settings did not take effect. This led me to hard-code t ...

Mastering Doctrine 2.1: Implementing "cascade: persist" with YAML configuration

Whenever I attempt to execute the following code, I encounter an error: $b = new B(); $a->addB($b); $entityManager->persist($a); It seems that I need to persist $b before adding it to $a. However, I am unable to do so and thus, I believe I need to ...