When my page loads, it displays:
Notice: Undefined variable: titleErr in index.php on line 141
I defined $titleErr at the beginning of my PHP, what else am I missing?
PHP:
<?php
    $titleErr = ''; 
    $title = '';
    function test_input($data) {
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        return $data;
    }
    if(isset($_GET)) {
        if (empty($_GET['page_title'])) {
            $titleErr = 'Name is required';
        } else {
            $title = test_input($_GET['page_title']);
        }
    }
?>
$(function() {
 $('form').submit(function(e) {
  $page_title =  $('input[name="page_title"]').val();
  e.preventDefault();
  $.ajax({
   method: 'GET',
   url: 'save_to_wp.php',
   datatype: 'json',
   data: {
    page_title: ($page_title)
   }
  });
 });<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div id = "save-dam" class = "tiny reveal" data-reveal>
        <form action = '<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>' class = "row">
            <div class = "small-12">
                <label>Save as</label>
            </div>
            <div class = "small-12">
                <input type = "text" placeholder = "Page Name" name="page_title" />
                <span class="error"><?php echo $titleErr;?></span>
            </div>
            <div class = "small-12">
                <button type = "submit" class = "button pill">Save</button>
            </div>
            <div class = "small-12">
                <button id="form-cancel" class = "button pill cancel">Cancel</button>
            </div>
        </form>
    </div>Help or suggestion would be greatly appreciated!
 
    