0

Fatal error: Call to undefined function get_header()

I can't get this working. I am using twentythirteen default theme shipped with wordpress. I have created a custom template called table.php and I also used <?php template name ?>. This custom template simply shows up all records in a database. Its working just fine but header and footer are missing and when I try to add header and footer of the current theme by adding get_header and get_footer, it throws a fatal error. Here is the code:

Just to mention, I used index.php that is inside twentythirteen folder, not from root folder where wp-config file or any other index.php for that matter.

<?php
/**
 * The main template file
 *
 * This is the most generic template file in a WordPress theme and one of the
 * two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * For example, it puts together the home page when no home.php file exists.
 *
 * @link http://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Twenty_Thirteen
 * @since Twenty Thirteen 1.0
 */

get_header(); ?>



<DIV class="form">

        <form method = "post"  action="<?php echo get_stylesheet_directory_uri(); ?>/dbentry.php">
            First Name: <input type="text" name = "first">*<?php echo $first_error;?><br>

            Last Name: <input type="text" name = "last">*<?php echo $last_error; ?><br>

            Email: &nbsp &nbsp &nbsp &nbsp    <input type="text" name = "email"><br>
            Telephone: <input type="number" name = "telephone">*<?php echo $tele_error; ?><br>

            Gender:&nbsp &nbsp 
            <input type="radio" name = "gender" value = "female">Female
            <input type="radio" name = "gender" value = "male">Male
            <br>

            <input type="submit" value ="submit" name="submit"><br>


        </form>
 </DIV>    

        <form action="<?php echo get_stylesheet_directory_uri(); ?>/tab.php"     method="post">
            <input type="submit" name = 'submit2' value = 'http://localhost/wordpress/?page_id=11'>
        </form>

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

Here is the code where the call will go after pressing the "Show all records" button.

<?php
    /**
     * The template for displaying all pages
     *
     * This is the template that displays all pages by default.
     * Please note that this is the WordPress construct of pages and that other
     * 'pages' on your WordPress site will use a different template.
     *
     * @package WordPress
     * @subpackage Twenty_Thirteen
     * @since Twenty Thirteen 1.0
     */

     /* 
     Template name: tab
     */

    get_header(); ?>

    <div class="table">
        <table class = "border">
            <?php

               require "db.php";

               if(isset($_POST['submit2'])){
                    $query = "SELECT * FROM person";
                    $result = mysqli_query($connection, $query);
                    $row = '';
                    $id = "";
                    echo "<tr>";
                    echo "<th><b>ID</b></th>";
                    echo "<th><b>FIRST</b></th>";
                    echo "<th><b>LAST</b></th>";
                    echo "<th><b>EMAIL</b></th>";
                    echo "<th><b>TELEPHONE</b></th>";
                    echo "<th><b>GENDER</b></th>";
                    echo "<th  scope='row'>EDIT</th>";
                    echo "<th>DELETE</th>";
                    echo "</tr>";
            echo "<tr>this is working just fine</tr>";
                    while($row = mysqli_fetch_array($result)){
                        $id = $row['ID'];
            echo $id ;

                        echo "<tr><td>".$row['ID']."</td><td>".$row['First']."</td><td>".$row['Last']."</td><td>".$row['Email']."</td><td>".$row['Telephone'].
                        "</td><td>".$row['Gender']."</td><td>"."<a href='edit.php?ID=$id'><input type='button' class = 'edit' value = 'Edit'></a>"."</td><td>"."<a href='delete.php?ID=$id'><input type='button' class = 'del' value='Delete'></a>"."</td></tr>";

                    }

                    mysqli_close($connection);

               } 
            ?>
        </table>
    </div>

    <table>
        <tr>jsdnsdjnsjd</tr>
    </table>



        <form action="form.php" method="post">
        <input type="submit" name="new" value="New Entry" class = "new">
        </form>




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

You can't load template files directly. WordPress is not loaded in that context, so you have no access to its functions. Create a page in WordPress admin, and assign your template to that page, then point your link to that page rather than directly to the template file.

  • I did that but if i simply attach a permalink to a button of that page the page title still shows up in top menu and also after assigning permalink to a button table.php does't show any database records but without page it works just fine but no header and footer of the theme. – Shah Apr 10 '14 at 7:45
  • If you want to exclude a page from a menu, that's a separate issue. For querying the database, you should be using the wpdb class. – Milo Apr 10 '14 at 15:38
0

https://codex.wordpress.org/Function_Reference/get_header

Maybe:Where is get_header('shop') file in Woocommerce templates

I hope I could help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.