473,395 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Record inserting twice

114 100+
Dear Sir,

Whenever I am trying to insert data into my database it inserts twice. Please help me.

The code is given below:

THE SQL TABLE:

CREATE TABLE `user` (
`id` int(11) NOT NULL auto_increment,
`iata` int(14) NOT NULL default '0',
`name` varchar(255) NOT NULL default '',
`email` varchar(255) NOT NULL default '',
`username` varchar(255) NOT NULL default '',
`password` varchar(255) NOT NULL default '',
`companyname` varchar(255) NOT NULL default '',
`date` datetime NOT NULL default '0000-00-00 00:00:00',
`city` varchar(255) NOT NULL default '',
`state` varchar(255) NOT NULL default '',
`province` varchar(255) NOT NULL default '',
`country` varchar(255) NOT NULL default '',
`phone` int(255) NOT NULL default '0',
`fax` int(255) NOT NULL default '0',
`cemail` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=3031 ;


The PHP code:


<?php

$iata = $_POST['iata'];
$name = $_POST['name'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = $_POST['password'];
$companyname = $_POST['companyname'];
$city = $_POST['city'];
$state = $_POST['state'];
$province = $_POST['province'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$cemail = $_POST['cemail'];

$query = ("INSERT INTO $SQL_USR_TBL (iata, name, email, username, password, companyname, date, city, state, province, country, phone, fax, cemail) values('$iata', '$name', '$email', '$username', '$password', '$companyname', now(), '$city', '$state','$province', '$country','$phone','$fax','$cemail')");

?>

Please help me Sir.

Thanks
Deepak
Dec 13 '06 #1
6 2255
really, what is the result of mysql_affected_rows() when you execute that query?
Dec 13 '06 #2
ronverdonk
4,258 Expert 4TB
This cannot be all the code you have in your script!
Usually this problem has to do with the program flow and sequence statements leading up to the execution of the insert command.

So, in order to be able to help here, show the code of the script you use and that causes this problem.

And show the code within the code tags!!!

Ronald :cool:
Dec 14 '06 #3
b1randon
171 Expert 100+
This cannot be all the code you have in your script!
Usually this problem has to do with the program flow and sequence statements leading up to the execution of the insert command.

So, in order to be able to help here, show the code of the script you use and that causes this problem.

And show the code within the code tags!!!

Ronald :cool:
An easy way to get multiple rows is with the mysql result object. If you're using one result to insert into another table and doing foreach that could be your problem. PHP actually puts two records for each column into the array. One record is at the column index (i.e. result[0][0]) and one is keyed by the name of the column (i.e. result[0][ColName]). Check for that problem.
Dec 14 '06 #4
subash
33
Hi Deepak,

This problem can be resolved on checking a session flag, Let me give you a brief description :

1. After the insertion has happen, just set a session variable "true"

2.Before inserting the command just check whether variable set as not-true


Example of the flow:

// Check the session variable value
// If it is not true - allow to the loop
if (condition)
{
// Insert statement

// Set the session variable to "true"

}


- Just try it and let me know how it works

Subash
Dec 18 '06 #5
ronverdonk
4,258 Expert 4TB
And don't forget to set it off again, otherwise you run into problems on subsequent (i.e. legal) inserts!

Aprt from that, I still think it is a logic/sequence problem in the code. So deepak, why don't you show us the code?

Ronald :cool:
Dec 18 '06 #6
subash
33
As Ronald said the session should be destroyed in the beginning of the file

Subash
Dec 18 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Mike Conklin | last post by:
This one really has me going. Probably something silly. I'm using dcount for a report to determine the number of different types of tests proctored in a semester. My report is based on a...
3
by: NuB | last post by:
I have an app that inserts records into a SQL db, I have a file that I'm reading to get the data out of, aka 'records', how can I determine of the record has been inserted into the database so i...
3
by: pjcraig | last post by:
This is driving me crazy! I have a form that a user will access from another form by selecting the item that they wish to view. When they open the new form, I pass through the id of the item they...
6
by: AA Arens | last post by:
Hi, I have a database with 2 main forms. Contacts and companies. I share the base with two others via LAN. On the companies form I have buttons to navigate throught the records (>400). We are...
1
by: Galka | last post by:
Hello I have a small database, where names of applicants are recorded with some other data. If an applicant telephones twice, he can be recorded twice. I am trying to check - by name. When...
3
by: veerapureddy | last post by:
Hai everybody, i like to insert some records into database from html form by entering data.my problem is how can i check , whether a record is available in database about a particular...
3
prn
by: prn | last post by:
Hi folks, I've got something that's driving me crazy here. If you don't want to read a long explanation, this is not the post for you. My problematic Access app is a DB for keeping track of...
0
omerbutt
by: omerbutt | last post by:
ih i have made an ASP page on which i am getting the values from a FORM and i am inserting those values into the AccessDatabase but the problem is that it is inserting each entry twice can any 1 help...
1
by: javediq143 | last post by:
Hi All, This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.