Why does a custom php code inside a custom template not get executed?

So in order to have some php code executed inside a page on wordpress there are 2 ways. One of them is to create a page template and when creating the new page in wordpress set the Page Attribute to this new page template.

This is what i have done.
I have created a custom template called stockchart.php.
I have copied the default content of page.php into it.
Then i added my php code below the first line

But it still doesnt work i dont know why?

Here is my custom template:

<?php /* Template Name: StockChart */ ?>

<?php print(“hello”) ?>

$dbHost = “xxx”;
$dbDatabase = “xxx”;
$dbPasswrod = “xxx”;
$dbUser = “xxx”;
$mysqli = mysqli_connect($dbHost, $dbUser, $dbPasswrod, $dbDatabase);

/* Getting stock1 table data */
$sql = “SELECT TradeDate as date, Lscore2 as L FROM levermann_kurz WHERE Stock_short=’AAPL’ ORDER BY TradeDate asc”;
$stock1 = mysqli_query($mysqli,$sql);
$stock1 = mysqli_fetch_all($stock1,MYSQLI_ASSOC);
$stock_dual = json_encode($stock1);

<?php get_header(); ?>

<div id=”primary” class=”content-area”>
<main id=”main” class=”site-main” role=”main”>
// Start the loop.
while ( have_posts() ) : the_post();

// Include the page content template.
get_template_part( ‘template-parts/content’, ‘page’ );

// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) {

// End of the loop.

</main><!– .site-main –>

<?php get_sidebar( ‘content-bottom’ ); ?>

</div><!– .content-area –>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Read more here:: Why does a custom php code inside a custom template not get executed?

Leave a Reply

Your email address will not be published. Required fields are marked *