Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,151,198 members, 7,811,525 topics. Date: Sunday, 28 April 2024 at 01:47 PM

Problem With Insert Statement Mysql - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Problem With Insert Statement Mysql (1402 Views)

How Can I Insert Registration Data Into MYSQL Database After Checking Checkbox / Lets Start A Real Web-deveopment Course Here Html+css+javascript+php+mysql / PHP Code To Insert And Retrieve Images From Mysql Server (2) (3) (4)

(1) (Reply) (Go Down)

Problem With Insert Statement Mysql by paranorman(m): 9:04pm On Apr 03, 2016
Anytime I use the simple INSERT statement to add a row to my table, row is added twice to the DB table:

INSERT INTO table_name VALUES
(value1, value2, value3);

I don't know'hat's wrong self.

Cc:
dhtm18, larisoft, et al...
Re: Problem With Insert Statement Mysql by noordean(m): 10:09pm On Apr 03, 2016
Post your real code
Re: Problem With Insert Statement Mysql by Nobody: 10:15pm On Apr 03, 2016
The code snippet you provided will most likely not even insert into the database as it is incomplete.

Possible causes could be:
You typed in the Insert statement twice,
Or you got your code mixed up somewhere,
But the cause cannot be from thE Database, it should be the queries that are faulty.., Provide your code in a more detailed way, If you want to hide sensitive info just replace it with example names that don't really exist in your Production/Development environment.
Re: Problem With Insert Statement Mysql by paranorman(m): 10:38pm On Apr 03, 2016
DanielTheGeek:
The code snippet you provided will most likely not even insert into the database as it is incomplete.

Possible causes could be:
You typed in the Insert statement twice,
Or you got your code mixed up somewhere,
But the cause cannot be from thE Database, it should be the queries that are faulty.., Provide your code in a more detailed way, If you want to hide sensitive info just replace it with example names that don't really exist in your Production/Development environment.
bros, all other statements works fine, except the INSERT statement.
I am just testing somethings out.
Table looks like:


CREATE TABLE tblCustomerDetails (
cutomerID INT(11) PRIMARY KEY AUTO_INCREMENT,
surname VARCHAR(30) NOT NULL,
lastname VARCAHR(30) NOT NULL,
);


now, when I use the UI provided by phpmyadmin (XAMPP) to enter values for a new row, it works fine. But when I write mysql code to enter a SINGLE row(of values), it adds double row to the table. It's really messing up my PK seqence. Bros, I dey check my sql statement wella, double check am self, still its 'malfunctioning'.
I am only working with SQL syntaxes. No PHP or any other language, just SQL.
Re: Problem With Insert Statement Mysql by Adesege(m): 11:16pm On Apr 03, 2016
The only reason why you are experiencing this is maybe cos your sql statement is enclosed in a loop or your browser is sending same information twice.

How are you sending your request? Is it thru ajax or normal POST/GET request?

You can paste the code you are using that's making the error for further scrutiny.

Regards
Re: Problem With Insert Statement Mysql by incredible6(m): 11:17pm On Apr 03, 2016
Did you open and close ur php tag properly...
Maybe you should also end database query .
Re: Problem With Insert Statement Mysql by Aphatech: 11:39am On Apr 04, 2016
You can post it to my signature, gurus are available all time...
Am not good at this aspect, learning continue
Re: Problem With Insert Statement Mysql by paranorman(m): 4:13pm On Apr 04, 2016
incredible6:
Did you open and close ur php tag properly...
Maybe you should also end database query .
bros, no other code collaboration, just MySQL. Do you get that? No PHP, no other code, just SQL!

The SQL INSERT ....... VALUES( ) code creates two rows instead of one!
Funny thing is that, when I used the UI provided in PhpMyAdmin (XAMPP, windows) to add a new row to the same table, it adds just a row! I don confuse die.
Re: Problem With Insert Statement Mysql by Silverman42(m): 2:03am On Apr 05, 2016
The correct syntax should be:
"INSERT INTO table_name (column1, column2, column3) VALUES (value1, value2, value3)"
Where value1, value2 and value3 = integer or character.
Re: Problem With Insert Statement Mysql by codemarshal08(m): 9:01am On Apr 05, 2016
Silverman42:
The correct syntax should be:
"INSERT INTO table_name (column1, column2, column3) VALUES (value1, value2, value3)"
Where value1, value2 and value3 = integer or character.

His syntax is valid. You are not always required to specify the column names.

1 Like

Re: Problem With Insert Statement Mysql by codemarshal08(m): 9:28am On Apr 05, 2016
@ paranorman
noordean:
Post your real code

Let us see the code that is not working properly.
Re: Problem With Insert Statement Mysql by TheWebDeveloper(m): 9:37am On Apr 05, 2016
Silverman42:
The correct syntax should be:
"INSERT INTO table_name (column1, column2, column3) VALUES (value1, value2, value3)"
Where value1, value2 and value3 = integer or character.

Thumbs up for 'best practice'.

@ OP:
If the SQL executes perfectly in phpMyAdmin, that is, once, then you're making two insert statements in your original script.

If you're using PHP, for instance, note the line number of the SQL in your text editor.
Now go up to the beginning of your script to check for any similar calls.

But here are my presumptions:
You might have created a function having that SQL and you changed the content of the same function. However, you're calling that function twice.
You might have created a loop(whatever for, as that would be absurd).

One thing is certain, you're using insert statement twice.

(1) (Reply)

Please I Need Sdk/api For Secugen Hamster Model: HSDUO3P / C++ Programming: To Do Or Not To Do. / Reasons Why Big Companies Hires ERP /CRM Admin/programmers

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 20
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.