如何从输入值向数据库插入值?

时间:2016-03-28 18:42:11

标签: php mysql

我对我的Wordpress网站上的Google地图自动填写的表单有疑问。

以下是发生的事情: - 我有一个表单来定位提交表单的用户周围的用户 - 有一个指针,一旦点击,地理定位用户然后提交表单并显示附近的用户

我尝试做的是获取指针从用户那里找到的坐标并将它们插入数据库中。

当用户点击该指针时,在结果页面中,他的坐标位于页面中,如下所示:

<input type="hidden" id="gmw-lat-1" class="gmw-lat gmw-lat-1" name="gmw_lat" value="xx.xxxxxxx">
<input type="hidden" id="gmw-long-1" class="gmw-lng gmw-long-1" name="gmw_lng" value="-xx.xxxxxxxxx">

有没有办法将这两个值保存到数据库中?

所以基本上: 在名为“wppl_friends_locator”的表中将“gmw_lat”和“gmw_long”填入登录用户的相应ID

我想的是:

UPDATE `wppl_friends_locator` SET `lat` = 'value_returned_from_the_input' WHERE `wppl_friends_locator`.`member_id` = logged_user_id;
UPDATE `wppl_friends_locator` SET `long` = 'value_returned_from_the_input' WHERE `wppl_friends_locator`.`member_id` = logged_user_id;

但我对如何做这样的事情以及放置它的地方没有任何反对意见。

编辑:

php文件中表单的代码:

<form class="standard-form gmw-form gmw-form-<?php echo $gmw['ID']; ?>" name="gmw_form" action="<?php echo $gmw['search_results']['results_page']; ?>" method="get">

        <?php do_action( 'gmw_search_form_start', $gmw ); ?>

        <?php do_action( 'gmw_search_form_before_address', $gmw ); ?>

        <div class="address-locator-wrapper">
            <!-- Address Field -->
            <?php gmw_search_form_address_field( $gmw, $id='', $class='' ); ?>

            <!--  locator icon -->
            <?php gmw_search_form_locator_icon( $gmw ); ?>
        </div>

        <?php do_action( 'gmw_search_form_before_xprofile', $gmw ); ?>

        <div class="xfield-trigger-wrapper">
            <div class="xfield-trigger" onclick="jQuery(this).closest('form').find('.gmw-fl-form-xprofile-fields').slideToggle();jQuery(this).html(jQuery(this).html() == 'Hide Options' ? 'Show Options' : 'Hide Options');">
                <?php echo $gmw['labels']['search_form']['show_options']; ?>
            </div>
        </div>

        <?php do_action( 'gmw_search_form_before_distance', $gmw ); ?>

        <!--distance values -->
        <?php gmw_search_form_radius_values( $gmw, $class='' ); ?>

        <!--distance units-->
        <?php gmw_search_form_units( $gmw, $class='' ); ?>  

        <?php gmw_fl_xprofile_fields( $gmw, $class='' ); ?>

        <?php gmw_form_submit_fields( $gmw, false ); ?>

        <?php do_action( 'gmw_search_form_end', $gmw ); ?>

    </form>

    <?php do_action( 'gmw_after_search_form', $gmw ); ?>

</div><!--form wrapper -->  

<?php do_action( 'gmw_after_search_form_template', $gmw ); ?>

表格的代码(输出):

<form class="standard-form gmw-form gmw-form-1" name="gmw_form" action="http://www.xxxxxxxxxxxxxxx" method="get">



        <div class="address-locator-wrapper">
            <!-- Address Field -->
            <div id="gmw-address-field-wrapper-1" class="gmw-address-field-wrapper gmw-address-field-wrapper-1 "><label class="gmw-field-label" for="gmw-address-1">Enter Address...</label><input type="text" name="gmw_address[]" id="gmw-address-1" autocomplete="off" class="gmw-address gmw-full-address gmw-address-1  " value="xxxxxxxxxxxxxxxxxxxx" placeholder=""><div class="gmw-locator-btn-wrapper gmw-locator-btn-within-wrapper"><i id="1" class="fa fa-map-marker gmw-locator-btn-within gmw-locator-button gmw-locate-btn gmw-locator-submit"></i><i id="gmw-locator-btn-loader-1" class="gmw-locator-btn-loader fa fa-refresh fa-spin" alt="Locator image loader" style="display:none;"></i></div></div>               
            <!--  locator icon -->
                    </div>


        <div class="xfield-trigger-wrapper">
            <div class="xfield-trigger" onclick="jQuery(this).closest('form').find('.gmw-fl-form-xprofile-fields').slideToggle();jQuery(this).html(jQuery(this).html() == 'Hide Options' ? 'Show Options' : 'Hide Options');">
                Show Options            </div>
        </div>


        <!--distance values -->
        <input type="hidden" name="gmw_distance" value="0.0378788">     
        <!--distance units-->
        <input type="hidden" name="gmw_units" value="imperial"> 

        <div class="gmw-fl-form-xprofile-fields gmw-fl-form-xprofile-fields-1 "><div class="editfield  gmw-1-field--wrapper"></div><div class="editfield textbox gmw-1-field-1-wrapper"><label for="gmw-1-field-1">Name</label><input type="text" name="field_1" id="gmw-1-field-1" class="field-1" value=""></div></div>       
        <div id="gmw-submit-wrapper-1" class="gmw-submit-wrapper gmw-submit-wrapper-1"> <input type="hidden" id="gmw-form-id-1" class="gmw-form-id gmw-form-id-1" name="gmw_form" value="1"> <input type="hidden" id="gmw-page-1" class="gmw-page gmw-page-1" name="paged" value="1"> <input type="hidden" id="gmw-per-page-1" class="gmw-per-page gmw-per-page-1" name="gmw_per_page" value="100"> <input type="hidden" id="prev-address-1" class="prev-address prev-address-1" value="xxxxxxxxxxxxxxxxxx"> <input type="hidden" id="gmw-lat-1" class="gmw-lat gmw-lat-1" name="gmw_lat" value="xxxxxxxxxxx"> <input type="hidden" id="gmw-long-1" class="gmw-lng gmw-long-1" name="gmw_lng" value="xxxxxxxxxxxxxx"> <input type="hidden" id="gmw-prefix-1" class="gmw-prefix gmw-prefix-1" name="gmw_px" value="fl"> <input type="hidden" id="gmw-action-1" class="gmw-action gmw-action-1" name="action" value="gmw_post"> <input type="submit" id="gmw-submit-1" class="gmw-submit gmw-submit-1" value="Submit"> </div>     

    </form>

结果页面:

<!--  Main results wrapper - wraps the paginations, map and results -->
<div class="gmw-results-wrapper gmw-results-wrapper-<?php echo $gmw['ID']; ?> gmw-fl-default-results-wrapper">

    <?php do_action( 'gmw_search_results_start' , $gmw ); ?>

    <div id="pag-top" class="pagination">

        <!-- results message -->
        <div class="pag-count" id="member-dir-count-top">
            <p><?php bp_members_pagination_count(); ?><?php gmw_results_message( $gmw, false ); ?></p>
        </div>

        <div class="clear"></div>

        <!-- per page -->
        <?php gmw_per_page( $gmw, $gmw['total_results'], 'paged' ); ?>

        <!-- pagination -->
        <div class="pagination-links" id="member-dir-pag-top">
            <?php gmw_pagination( $gmw, 'paged', $gmw['max_pages'] ); ?>
        </div>
    </div>

    <div class="clear"></div>

    <!-- GEO my WP Map -->
    <?php 
    if ( $gmw['search_results']['display_map'] == 'results' ) {
        gmw_results_map( $gmw );
    }
    ?>

    <?php do_action( 'bp_before_directory_members_list' ); ?>

    <ul id="members-list" class="item-list" role="main">

        <!-- members loop -->
        <?php while ( bp_members() ) : bp_the_member(); ?>

            <!-- do not remove this line -->
            <?php $member = $members_template->member; ?>
            <li>         
                <!-- do not remove this line -->
                <?php do_action( 'gmw_search_results_loop_item_start', $gmw, $member ); ?>

                <!-- avatar -->
                <?php if ( isset( $gmw['search_results']['avatar']['use'] ) ) { ?>
                    <div class="item-avatar">
                        <a href="<?php bp_member_permalink(); ?>">
                            <?php bp_member_avatar( array( 'type' => 'full', 'width' => $gmw['search_results']['avatar']['width'], 'height' => $gmw['search_results']['avatar']['height'] ) ); ?>
                        </a>
                    </div>
                <?php } ?>

                <div class="item">

                    <div class="item-title">


                        <!-- member name -->
                        <a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a>

                        <?php do_action( 'gmw_search_results_before_distance', $gmw, $member); ?>

                        <!-- distance -->
                        <?php gmw_distance_to_location( $members_template->member, $gmw ); ?>

                        <?php if ( bp_get_member_latest_update() ) { ?>
                            <span class="update"> <?php bp_member_latest_update(); ?></span>
                        <?php }; ?>

                    </div>

                    <div class="item-meta">
                        <span class="activity">
                            <?php bp_member_last_active(); ?>
                        </span>
                    </div>

                    <?php do_action( 'bp_directory_members_item' ); ?>
                    <?php do_action( 'gmw_fl_search_results_member_items', $gmw, $member ); ?>

                    <?php
                    /*                     * *
                     * If you want to show specific profile fields here you can,
                     * but it'll add an extra query for each member in the loop
                     * (only one regardless of the number of fields you show):
                     *
                     * bp_member_profile_data( 'field=the field name' );
                     */
                    ?>
                </div>

                <div class="action">
                    <?php do_action( 'bp_directory_members_actions' ); ?>
                </div>

                <div class="clear"></div>

                <?php do_action( 'gmw_search_results_before_address', $gmw, $member ); ?>

                <!-- address -->


                <!-- Get directions -->     
                <?php if ( isset( $gmw['search_results']['get_directions'] ) ) { ?>
                    <?php global $members_template; ?>
                    <div class="get-directions-link">
                        <?php gmw_directions_link( $members_template->member, $gmw, $gmw['labels']['search_results']['directions'] ); ?>
                    </div>
                <?php } ?>

                <!--  Driving Distance -->
                <?php if ( isset( $gmw['search_results']['by_driving'] ) ) { ?>
                    <?php gmw_driving_distance( $member, $gmw, false ); ?>
                <?php } ?>

                <?php do_action( 'gmw_search_results_loop_item_end', $gmw, $member ); ?>

            </li>

        <?php endwhile; ?>

    </ul>

    <?php do_action( 'bp_after_directory_members_list' ); ?>

    <?php bp_member_hidden_fields(); ?>

    <div id="pag-bottom" class="pagination">

        <!-- results message -->
        <div class="pag-count" id="member-dir-count-top">
            <p><?php bp_members_pagination_count(); ?></p>
        </div>

        <div class="clear"></div>

        <!-- per page -->
        <?php gmw_per_page( $gmw, $gmw['total_results'], 'paged' ); ?>

        <!-- pagination -->
        <div class="pagination-links" id="member-dir-pag-top">
            <?php gmw_pagination( $gmw, 'paged', $gmw['max_pages'] ); ?>
        </div>

    </div>

    <?php do_action( 'gmw_search_results_end', $gmw ); ?>   

</div>

1 个答案:

答案 0 :(得分:0)

表单中的隐藏字段可以通过POST或GET提交,就像其他表单字段一样。在PHP中,您可以使用$_GET['name']$_POST['name']

访问这些内容