Jump to content


Photo

Insert occurs twice, no idea why!


  • Please log in to reply
7 replies to this topic

#1 shadowcaster

shadowcaster
  • Members
  • PipPip
  • Member
  • 22 posts
  • LocationUK

Posted 30 March 2006 - 06:24 PM

Hello.
I've been searching all over the internet for an answer to this problem but I'm still stuck. I have a table in my DB that was made with this code:

CREATE TABLE searches (id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, search VARCHAR(255) NOT NULL, datum DATE NOT NULL)

and I am using PHP to insert searches into it like so:
<?php
$date = date('Y-m-d');
$queryW = "INSERT DELAYED INTO searches VALUES (NULL, '$search','$date')";
mysql_query($queryW) or print('Problem adding to Db: '.mysql_error()); ?>

But it inserts the same record twice and I have no idea why it does that. As far as I can see my php is sound and other inserts work fine. Please help.
--Lurking out of sight, Night shall fall and feed my frenzy, Beneath an eerie moon a change comes over me--[br]Check out Symphony X (The oddysey album) if you like heavy metal

#2 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 30 March 2006 - 06:38 PM

Nothing wrong with what you posted.. is there some kind of refresh or redirection that could cause the page to be loaded twice with the same input?

#3 shadowcaster

shadowcaster
  • Members
  • PipPip
  • Member
  • 22 posts
  • LocationUK

Posted 31 March 2006 - 10:50 PM

unfortunatly no, I've checked numerous times and I have made use of php's require_once() function and even placed it with other insert SQL commands and it still does the same thing. Every other insert works fine but this doesn't want to work. I have resorted to using the DISTINCT keyword in my queries to stop the doubling from displaying when I read from the database.
--Lurking out of sight, Night shall fall and feed my frenzy, Beneath an eerie moon a change comes over me--[br]Check out Symphony X (The oddysey album) if you like heavy metal

#4 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 31 March 2006 - 11:11 PM

are you using an if() to check if it was successful? i have a feeling you are putting the mysql_query($queryW) into an if, which runs it again (after already having run it) to check if it was successful.

#5 shadowcaster

shadowcaster
  • Members
  • PipPip
  • Member
  • 22 posts
  • LocationUK

Posted 02 April 2006 - 10:09 PM

Can you please give me an example. Do you mean like this?:
if (mysql_query("INSERT INTO searches VALUES('NULL, '$search','$date')")){
  //do stuff
}
I haven't done that no.
--Lurking out of sight, Night shall fall and feed my frenzy, Beneath an eerie moon a change comes over me--[br]Check out Symphony X (The oddysey album) if you like heavy metal

#6 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 02 April 2006 - 10:16 PM

Are you sure it's inserting twice? Maybe the query you're using to look at the data is flawed (a missing join condition or something). Have you viewed the data with phpMyAdmin or something like that?

Just a thought.. I don't know where to go on this one, except maybe look through a much larger section of code.

#7 khendar

khendar
  • Members
  • PipPipPip
  • Advanced Member
  • 78 posts

Posted 03 April 2006 - 01:51 AM

Just a hunch - try removing the DELAYED command to see if thats causing a problem somehow.

#8 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 03 April 2006 - 09:37 AM

You definitely need to verify that you're only getting to that query once -- either make it a function, or add a print statement. You need to isolate the cause of the duplication.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users