muazzamazaz
Forum Replies Created
Viewing 4 replies - 1 through 4 (of 4 total)
-
Forum: Fixing WordPress
In reply to: Code IssueThe whole code in PHP file:
<?php // embed the javascript file that makes the AJAX request wp_enqueue_script( 'my-ajax-request',get_template_directory_uri() . '/js/countclicks.js', array( 'jquery' ) ); // declare the URL to the file that handles the AJAX request (wp-admin/admin-ajax.php) wp_localize_script( 'my-ajax-request', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); add_action('wp_ajax_my_action', 'my_action_callback'); add_action('wp_ajax_nopriv_my_action', 'my_action_callback'); function my_action_callback() { global $wpdb; if($wpdb->insert( 'shopping_list', array( 'user_id'=>$current_user->ID, 'title'=>$_POST['title'], 'shopping_list'=>$_POST['shopping_list'], 'delivery_date'=>$_POST['delivery_date'], 'creation_time'=>date, 'delivery_slot'=>$_POST['delivery_slot'], //'has_file'=>$_REQUEST['has_file'], 'instruction'=>$_POST['instruction'], 'address'=>$_POST['address'] ) ) != false) { echo 'INSERT SUCCESSFUL'; } else { echo 'INSERT FAILED'; } die(); }
Forum: Fixing WordPress
In reply to: Code Issueglobal $wpdb don’t have direct access as shows no error when using its function and even not insert and record. Don’t have dbname property value inside it.
Forum: Fixing WordPress
In reply to: Code IssueThe following JS file code has solved the problem and PHP function getting values.
jQuery(document).ready(function($) { $('#placeorder').click(function(){ // data = {action: 'my_action'}; var dataString = {action: 'my_action', 'title' : $('#title').val(), 'shopping_list' : $('#shopping_list').val(), 'delivery_date' : $('#delivery_date').val(), 'delivery_slot' : $('#delivery_slot').val(), 'special_instructions' : $('#special_instructions').val(), 'address' : $('#address').val() }; $.post(MyAjax.ajaxurl, dataString, function(response) { // This is where we alert the response alert('Got this from the server: ' + response); }); }); });
Thank You So Much.
Forum: Fixing WordPress
In reply to: Code IssueIt works fine for getting function into action.
I need to write insertion query in function like:
$wpdb->insert( 'shopping_list', array('user_id'=>$current_user->ID, 'title'=>$_POST['title'], 'shopping_list'=>$_POST['shopping_list'], 'delivery_date'=>$_POST['delivery_date'], 'creation_time'=>date, 'delivery_slot'=>$_POST['delivery_slot'], 'instruction'=>$_POST['instruction'], 'address'=>$_POST['address'] ) );
What changes should be in file.
Viewing 4 replies - 1 through 4 (of 4 total)