Jump to content

Double Entry


herghost

Recommended Posts

Hi all,

 

for some reason my form action script is entering everything into the database twice? Whats causing this?

<?php
session_start();
//Customer Details
include('../config/connect.php');


$title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
$forename = (isset($_POST['forename'])) ? trim($_POST['forename']) : '';
$surname = (isset($_POST['surname'])) ? trim($_POST['surname']) : '';
$company = (isset($_POST['company'])) ? trim($_POST['company']) : '';
$nameno = (isset($_POST['nameno'])) ? trim($_POST['nameno']) : '';
$fline = (isset($_POST['fline'])) ? trim($_POST['fline']) : '';
$sline = (isset($_POST['sline'])) ? trim($_POST['sline']) : '';
$city = (isset($_POST['city'])) ? trim($_POST['city']) : '';
$state = (isset($_POST['state'])) ? trim($_POST['state']) : '';
$zip = (isset($_POST['zip'])) ? trim($_POST['zip']) : '';
$country = (isset($_POST['country'])) ? trim($_POST['country']) : '';
$tax = (isset($_POST['tax'])) ? trim($_POST['tax']) : '';

//Contact Details
$email = (isset($_POST['email'])) ? trim($_POST['email']) : '';
$phone = (isset($_POST['phone']))? trim($_POST['phone']) : '';
$fax = (isset($_POST['fax'])) ? trim($_POST['fax']) : '';

//Account Details
$username = (isset($_POST['username'])) ? trim($_POST['username']) : '';
$password = (isset($_POST['password'])) ? md5($_POST['password']): '';
$newsleter = (isset($_POST['newsletter'])) ? trim($_POST['newsletter']) : '';


$query = "INSERT INTO customers (title, forename, surname, company, nameno, fline, sline, city, state, zip, country, tax, email, phone, fax, username, password, newsletter)

VALUES

('$title', '$forename', '$surname', '$company', '$nameno', '$fline', '$sline', '$city', '$state', '$zip', '$country', '$tax', '$email', '$phone', '$fax', '$username', '$password', '$newsletter')
";
$result = mysql_query($query);
if (!mysql_query($query))
  {
  die('Error: ' . mysql_error());
  }

$_SESSION['addedcustomer'] = 'addedcustomer';
header ('Location: ../home.php');

?>

 

Link to comment
https://forums.phpfreaks.com/topic/194341-double-entry/
Share on other sites

You have two mysql_query() statements in your code, so of course you will get double entries - 

$result = mysql_query($query);
if (!mysql_query($query))

 

Computers only do exactly what their code tells them to do. Why does your code execute the query once, then a second time?

Link to comment
https://forums.phpfreaks.com/topic/194341-double-entry/#findComment-1022341
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.