I'm working off of a local install. Just experimenting and going by this tutorial:
http://www.makeuseof.com/tag/tutorial-ajax-wordpress/
This is about using AJAX to create a form for database entries. The author wants you to add the following code to your functions.php:
<? php
wp_enqueue_script('jquery');
function newTitle(){
global $wpdb; $title = $_POST['title'];
$year = $_POST['year'];
$genre = $_POST['genre'];
$link = $_POST['link'];
$decade = $_POST['decade'];
if($wpdb->insert('films.titles',array( 'title'=>$title, 'year'=>$year, 'genre'=>$genre, 'link'=>$link, 'decade'=>$decade ))===FALSE){
echo "Error";
} else {
echo "Title '".$title. "' successfully added, row ID is ".$wpdb->insert_id;
} die();
}
add_action('wp_ajax_newTitle', 'newTitle');
add_action('wp_ajax_nopriv_newTitle', 'newTitle'); // not really needed
I changed the names of the variables and names for the forms to accord with the database I'm using as an example.
But, when this code is saved two things happen:
1 - some of the code prints out at the top of the wordpress admin screen. Doesn't matter what section of the admin I'm looking at, the code will appear at the top of the screen. It starts with all the code from just after the if($wpbd->
and prints out everything after. So, the printed code is:
"insert('films.titles',array( 'title'=>$title, 'year'=>$year, 'genre'=>$genre, 'link'=>$link, 'decade'=>$decade ))===FALSE){ echo "Error"; } else { echo "Title '".$title. "' successfully added, row ID is ".$wpdb->insert_id; } die(); } add_action('wp_ajax_newTitle', 'newTitle'); add_action('wp_ajax_nopriv_newTitle', 'newTitle'); // not really needed"
I'm not backticking it because that's the way it appears on the screen.
2 - When I view the site there is gray space created below the header. It's about the size of the header and separates the header from the side column. (this is the twentyfourteen theme). If I delete the code from the functions.php everything goes back to normal. This is the only code in the functions.php for the file in the child theme.
****EDIT****
I tried the bit about adding the end bracket for php the '?>' and making sure there was no whitespace afterwards. That's not the problem.