Jump to content

Archived

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

shadowcaster

Insert occurs twice, no idea why!

Recommended Posts

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:
[code]<?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()); ?>[/code]

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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Can you please give me an example. Do you mean like this?:
[code]
if (mysql_query("INSERT INTO searches VALUES('NULL, '$search','$date')")){
  //do stuff
}[/code]
I haven't done that no.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Just a hunch - try removing the DELAYED command to see if thats causing a problem somehow.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.