[英]I'm trying to display data from my database in table, but don't want to appear, I don't know what went wrong
[英]Data saved twice in MySQL database. Don't know what I do wrong?
我正在网站上的某项功能上工作。 我使用OSM和Leaflet实现了交互式地图,我希望用户向此地图添加位置报告。
虽然,我遇到的第一个问题是当用户添加位置报告时,正在发送到网站MySQL数据库的数据已被两次注册,这是不应该的。
恳请您查看我的代码并搜索任何会重复我的数据的内容。
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');
让我知道是否需要更多信息来了解正在发生的事情。
先感谢您。
最好的祝福,
金
检查数据库架构,这可能是数据库架构错误的原因,例如错误的主键/外键或缺少某些字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.