数据在MySQL数据库中保存两次。不知道我做错了什么? [英] Data saved twice in MySQL database. Don't know what I do wrong?

查看:167
本文介绍了数据在MySQL数据库中保存两次。不知道我做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用我网站上的功能。我使用OSM和Leaflet实现了交互式地图,我希望用户将位置报告添加到此地图。尽管我遇到的第一个问题是当用户添加位置报告时,发送到网站MySQL数据库的数据被注册了两次,它不应该被注册。



我恳请您查看我的代码并搜索任何可能会复制我的数据的内容。

 函数map_location_report_form()
{

if(current_user_can('create_users'))
{

global $ wpdb;

$ this_page = $ _SERVER ['REQUEST_URI'];
$ page = $ _POST ['page'];

if $($ page == NULL)
{
echo'< form method =postaction ='。$ this_page。'>

< div class =formfield-reportid =formfield-report-firstname>
< label for =first_nameid =first_name> Navn:< / label>
< input type =textname =first_nameid =first_name/>
< / div>

< div class =formfield-reportid =formfield-report-lastname>
< label for =last_nameid =last_name> Efternavn:< / label>
< input type =textname =last_nameid =last_name/>
< / div>

< div class =formfield-reportid =formfield-report-locationtype>
< label for =location_typeid =location_type>结束类型:< / label>
< select name =location_type/>
< option value =sigtmeldingselected> Sigtmelding< / option>
< option value =fangstrapport> Fangstrapport< / option>
< option value =jagtomraade>Jagtområde< / option>
< / select>
< / div>

< div class =formfield-reportid =formfield-report-latitude>
< label for =location_latitudeid =location_latitude> Breddegrad:< / label>
< input type =textname =location_latitudeid =location_latitude/>
< / div>

< div class =formfield-reportid =formfield-report-longitude>
< label for =location_longitudeid =location_longitude>Længdegrad:< / label>
< input type =textname =location_longitudeid =location_longitude/>
< / div>

< input type =hiddenvalue =1name =page/>

< div id =formfield-report-button>
< input class =btn btn-default submit-form-b​​uttontype =Submit/>
< / div>

< / form>';
}
elseif($ page == 1)
{
$ first_name = $ _POST ['first_name'];
$ last_name = $ _POST ['last_name'];
$ location_type = $ _POST ['location_type'];
$ location_latitude = $ _POST ['location_latitude'];
$ location_longitude = $ _POST ['location_longitude'];
$ b $ page_one_inputs = array

'first_name'=> $ first_name,
'last_name'=> $ last_name,
'location_type' => $ location_type,
'location_latitude'=> $ location_latitude,
'location_longitude'=> $ location_longitude,
'page'=> $ page
);

$ page_one_table ='maplocationreports';

$ insert_page_one = $ wpdb->插入($ page_one_table,$ page_one_inputs);

echo'< h3> Mange tak for dit bidrag!< / h3>';
echo'< p> Der er sat stor prispåat du har taget dig tid til at registrere et punktpåkortet!< / p>';
}

}
else
{
echo'< p>在udvikling下的Desværreer denne service< / p>
< p>用于互动的Mange tak。< / p>';
}
};

add_shortcode('map_location_report','map_location_report_form');

让我知道是否需要更多信息来了解正在发生的事情。

预先感谢您。



祝好,

检查你的数据库模式,它可能是错误的数据库模式的原因,比如不正确的主键/外键或者是不正确的主键/外键有些领域缺失。


I am working on a feature on my website. I implemented a interactive map using OSM and Leaflet and I would like users to add location reports to this map.

Although, the first issue i ran into is when the users are adding a location report the data that is being send to the websites MySQL database is registered twice which it should not.

I kindly ask you to take a look at my code and search for any thing that would duplicate my data.

function map_location_report_form()
{

    if( current_user_can( 'create_users' )) 
    {

        global $wpdb;

        $this_page  =   $_SERVER['REQUEST_URI'];
        $page       =   $_POST['page'];

        if ( $page == NULL ) 
        {
            echo '<form method="post" action="' . $this_page .'">

                    <div class="formfield-report" id="formfield-report-firstname">
                        <label for="first_name" id="first_name">Navn: </label>
                        <input type="text" name="first_name" id="first_name" />
                    </div>

                    <div class="formfield-report" id="formfield-report-lastname">
                        <label for="last_name" id="last_name">Efternavn: </label>
                        <input type="text" name="last_name" id="last_name" />
                    </div>

                    <div class="formfield-report" id="formfield-report-locationtype">
                        <label for="location_type" id="location_type">Rapport type: </label>
                        <select name="location_type" />
                            <option value="sigtmelding" selected>Sigtmelding</option>
                            <option value="fangstrapport">Fangstrapport</option>
                            <option value="jagtomraade">Jagtområde</option>
                        </select>
                    </div>

                    <div class="formfield-report" id="formfield-report-latitude">
                        <label for="location_latitude" id="location_latitude">Breddegrad: </label>
                        <input type="text" name="location_latitude" id="location_latitude" />
                    </div>

                    <div class="formfield-report" id="formfield-report-longitude">
                        <label for="location_longitude" id="location_longitude">Længdegrad: </label>
                        <input type="text" name="location_longitude" id="location_longitude" />
                    </div>

                    <input type="hidden" value="1" name="page" />

                    <div id="formfield-report-button">
                        <input class="btn btn-default submit-form-button" type="Submit" />
                    </div>

            </form>';               
        }
        elseif ( $page == 1 ) 
        {
            $first_name             =   $_POST['first_name'];
            $last_name              =   $_POST['last_name'];    
            $location_type          =   $_POST['location_type'];
            $location_latitude      =   $_POST['location_latitude'];
            $location_longitude     =   $_POST['location_longitude'];

            $page_one_inputs =  array
            (
                'first_name'            => $first_name,
                'last_name'             => $last_name,
                'location_type'         => $location_type,
                'location_latitude'     => $location_latitude,
                'location_longitude'    => $location_longitude,
                'page'                  => $page
            );

            $page_one_table = 'maplocationreports';

            $insert_page_one = $wpdb->insert($page_one_table, $page_one_inputs);

            echo '<h3>Mange tak for dit bidrag!</h3>';
            echo '<p>Der er sat stor pris på at du har taget dig tid til at registrere et punkt på kortet!</p>';
        }

    }
    else 
    {
        echo    '<p>Desværre er denne service under udvikling.</p>
                 <p>Mange tak for din interesse.</p>';
    }   
};

add_shortcode('map_location_report','map_location_report_form');

Let me know if more information is necessary to understand what is going on.

Thank you in advance.

Best regards,

Kim

解决方案

Check your database schema, it can be cause of wrong database schema like incorrect primary key/foreign key or some field missing.

这篇关于数据在MySQL数据库中保存两次。不知道我做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆