zimmo Posted April 13, 2010 Share Posted April 13, 2010 Thanks for peoples assistance todate. I am moving forward thanks to this great site. I am not sure where this has gone wrong, I know it will be something in the wrong place. I am performing a check first to see if entry exists, if it does not then to insert, if it does then update. There is no entry at the moment, and when I click submit it is sending the form off even though I have not entered any data, it should error check to make sure certain fields have information? Where have I gone wrong? <?php session_start(); if (!(isset($_SESSION['username']) && $_SESSION['username'] != '')) { header ("Location: login.html"); } // Include the connections script to make a database connection. include("inc/connect.php"); if ( $_POST['submit'] ) { $primary_contact = $_POST['primary_contact']; $address_1 = $_POST['address_1']; $address_2 = $_POST['address_2']; $address_3 = $_POST['address_3']; $town = $_POST['town']; $county = $_POST['county']; $postcode = $_POST['postcode']; $email = $_POST['email']; $telephone_1 = $_POST['telephone_1']; $telephone_2 = $_POST['telephone_2']; $fax = $_POST['fax']; if ( empty($primary_contact) ) { $error['primary_contact_error'] = '<div class="formerror">Please enter your Primary Contact Name.</div>'; } if ( empty($town) ) { $error['town_error'] = '<div class="formerror">Please Enter your Town/City.</div>'; } if ( empty($county) ) { $error['county_error'] = '<div class="formerror">Please Select your County.</div>'; } if ( empty($postcode) ) { $error['postcode_error'] = '<div class="formerror">Please enter your Postcode.</div>'; } if ( empty($telephone_1) ) { $error['telephone_1_error'] = '<div class="formerror">Please enter your Main Telephone Number.</div>'; } // End of error checking, all fields covered. $sql = "SELECT * FROM details WHERE fishery_id = '$_SESSION[fishery_id]' "; $sql_result = mysql_query($sql); if (mysql_num_rows($sql_result) ==0) { // Start of insert // The form should post to itself. if (!$error) { # setup SQL statement $SQL = " INSERT INTO details "; $SQL = $SQL . " (fishery_id, venue_name, primary_contact, address_1, address_2, address_3, town, county, postcode, email, telephone_1, telephone_2, fax) VALUES "; $SQL = $SQL . " ('$_SESSION[fishery_id]', '$_SESSION[venue_name]', '$primary_contact', '$address_1', '$address_2', '$address_3', '$town', '$county', '$postcode', '$email', '$telephone_1', '$telephone_2', '$fax') "; #execute SQL statement $result = mysql_db_query( *****,"$SQL",$connection ); # check for error if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } } } // END of insert else { // Start of update // The form should post to itself. if (!$error) { # setup SQL statement $SQL = " UPDATE details SET venue_name = '{$_SESSION[venue_name]}', primary_contact = '{$_POST['primary_contact']}', address_1 = '{$_POST['address_1']}', address_2 = '{$_POST['address_2']}', address_3 = '{$_POST['address_3']}', town = '{$_POST['town']}', county = '{$_POST['county']}', postcode = '{$_POST['postcode']}', email = '{$_POST['email']}', telephone_1 = '{$_POST['telephone_1']}', telephone_2 = '{$_POST['telephone_2']}', fax = '{$_POST['fax']}' WHERE fishery_id = '$_SESSION[fishery_id]' "; #execute SQL statement $result = mysql_db_query( *****,"$SQL",$connection ); # check for error if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } } } // End of update header("Location: http://www.******.com/development/admin/details_view.html"); exit; } ?> Link to comment https://forums.phpfreaks.com/topic/198404-error-check-getting-skipped/ Share on other sites More sharing options...
andrewgauger Posted April 13, 2010 Share Posted April 13, 2010 header ("Location: login.html"); should be followed by exit; Link to comment https://forums.phpfreaks.com/topic/198404-error-check-getting-skipped/#findComment-1041131 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.