shadowcaster Posted March 30, 2006 Share Posted March 30, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/6195-insert-occurs-twice-no-idea-why/ Share on other sites More sharing options...
wickning1 Posted March 30, 2006 Share Posted March 30, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/6195-insert-occurs-twice-no-idea-why/#findComment-22366 Share on other sites More sharing options...
shadowcaster Posted March 31, 2006 Author Share Posted March 31, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/6195-insert-occurs-twice-no-idea-why/#findComment-22766 Share on other sites More sharing options...
akitchin Posted March 31, 2006 Share Posted March 31, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/6195-insert-occurs-twice-no-idea-why/#findComment-22772 Share on other sites More sharing options...
shadowcaster Posted April 2, 2006 Author Share Posted April 2, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/6195-insert-occurs-twice-no-idea-why/#findComment-23261 Share on other sites More sharing options...
wickning1 Posted April 2, 2006 Share Posted April 2, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/6195-insert-occurs-twice-no-idea-why/#findComment-23266 Share on other sites More sharing options...
khendar Posted April 3, 2006 Share Posted April 3, 2006 Just a hunch - try removing the DELAYED command to see if thats causing a problem somehow. Quote Link to comment https://forums.phpfreaks.com/topic/6195-insert-occurs-twice-no-idea-why/#findComment-23331 Share on other sites More sharing options...
fenway Posted April 3, 2006 Share Posted April 3, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/6195-insert-occurs-twice-no-idea-why/#findComment-23427 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.