Hi I have created this script to add Airfield information to a database using a form, it works OK except that I always get a duplicate entry int the database. Can someone tell me how I just get a single entry in.
I am not a .php programmer, I have just thrown this together using examples and tutorials. I am sure it is a simple error in the code but I cannot spot it.
[php]<?php
$page_title = ‘Add airfield’;
$page_heading = ‘Add Airfield’;
include(‘includes/header.php’);
echo ‘
Insert New Airfield Record
’;$_id = getVar(‘id’);
// if user isn’t logged in as admin
if (! $user_info[‘is_admin’]) {
ssi_login (BASE_HREF . ‘addairfield.php’, ‘echo’);
include(‘includes/footer.php’);
exit(0);
}
$_submit = getVar(‘submit’);
$_icao = getVar(‘icao’);
$_airfieldName = getVar(‘airfieldName’);
$_lat = getVar(‘lat’);
$_lon = getVar(‘lon’);
$_elevation = getVar(‘elevation’);
$_mainRunwayHeading = getVar(‘mainRunwayHeading’);
if ($_submit == ‘Add Record’) {
// setup SQL statement
$sql = “INSERT INTO glider_fields SET icao=’” . $_icao . “’, name=’” . $_airfieldName . “’, lat=’” . $_lat . “’, lon=’” . $_lon . “’, elevation=’” . $_elevation . “’, main_rwy=’” . $_mainRunwayHeading . “’”;
// execute SQL statement
$result = mysql_query($sql);
// check submission
if( ($result = mysql_query($sql, $GLOBALS['db'])) and (mysql_affected_rows($GLOBALS['db']) == 1) ) {
echo '<p>Successfully added ' . $_name . ' (' . $_icao . ') to airfield database.</p>';
}
else {
echo '<p>Error adding ' . $_name . ' (' . $_icao . ') to airfield database!</p>';
}
}
echo ‘’;
echo ‘
ICAO: | |
Airfield Name: | |
Latitude (Dec Minutes): | |
Longitude (Dec Minutes): | |
Elevation (Feet ASL): | |
Main Runway Heading: | |
echo ’ ';
include(‘includes/footer.php’);
?>[/php]