Wanyika Posted September 8, 2010 Share Posted September 8, 2010 Having a problem with that "insert ignore into". If it is a new record, it works, when it is a excisting record that needs to be updated, it is giving me this error: Cannot execute query: INSERT IGNORE INTO (gedcom,kennel) VALUES ("World","Avongara") What or where is it going wrong? This message is for me not enough to find the problem. $kennels = array(); if( !in_array( $kennel, $kennels ) ) array_push( $kennels, $kennel ); foreach( $kennels as $kennel ) { $query = "INSERT IGNORE INTO $kennels_table (gedcom,kennel) VALUES (\"$tree\",\"$kennel\")"; $result = @mysql_query( $query ) or die ("$admtext[cannotexecutequery]: $query"); } Thanks for helping Quote Link to comment https://forums.phpfreaks.com/topic/212911-insert-ignore-into-error/ Share on other sites More sharing options...
rwwd Posted September 8, 2010 Share Posted September 8, 2010 Hi there, I wonder what other error messages you are masking by using the error suppressor on the beginning of the mysql_query() function, I would have thought that the more info you got from the function the better? And personally (shouldn't affect the running) I would do my sql statement like this:- $query = "INSERT IGNORE INTO `".$kennels_table."` (`gedcom`,`kennel`) VALUES ('".$tree."','".$kennel."') "; That at least now has single quotes around the string values, you don't need single quotes around numerical values (ints) as this will cause error's or at least make them harder to find in the longrun. Hope that makes sense anyway. Cheers, Rw Quote Link to comment https://forums.phpfreaks.com/topic/212911-insert-ignore-into-error/#findComment-1108928 Share on other sites More sharing options...
Wanyika Posted September 8, 2010 Author Share Posted September 8, 2010 Thanks for the fast reply. When changing it to your version it is still giving me the same error but with ``after the INTO: Cannot execute query: INSERT IGNORE INTO `` (`gedcom`,`kennel`) VALUES ('World','Avongara') before it was: Cannot execute query: INSERT IGNORE INTO (gedcom,kennel) VALUES ("World","Avongara") Not enough for me to find the problem. Quote Link to comment https://forums.phpfreaks.com/topic/212911-insert-ignore-into-error/#findComment-1108949 Share on other sites More sharing options...
DavidAM Posted September 9, 2010 Share Posted September 9, 2010 If you ask, the server will tell you what is wrong. Add mysql_error() to your "error handler". $result = @mysql_query( $query ) or die ("$admtext[cannotexecutequery]: $query\n" . mysql_error()); I do not use nor recommend the error suppression operator (@) and I do not use nor recommend "or die()" -- I just copied your code and added a little bit to it. Note: You do not need the backticks ( ` ) around column names unless they are reserved words. Oh, wait a minute: look at your query, there is no way that query is working at all: INSERT IGNORE INTO (gedcom,kennel) VALUES ("World","Avongara") There is no table name there. It needs to be INSERT IGNORE INTO tablename (gedcom,kennel) VALUES ("World","Avongara") It looks like $kennels_table does not have a value. Quote Link to comment https://forums.phpfreaks.com/topic/212911-insert-ignore-into-error/#findComment-1109001 Share on other sites More sharing options...
Wanyika Posted September 9, 2010 Author Share Posted September 9, 2010 Hi, Yes i saw that also at 03.00AM but did go to sleep. Todayy I truncate all tables and the strange thing is that when adding a record, it is doing what it needs to do. If i echo the query it gives me: INSERT IGNORE INTO tng_breeders (gedcom,breeder) VALUES ("World","Unknown Breeder") You see there is a table name. Is there a reason why it fails when adding a lot of records? I start putting back data in the tables and see when it starts to fail again. Quote Link to comment https://forums.phpfreaks.com/topic/212911-insert-ignore-into-error/#findComment-1109112 Share on other sites More sharing options...
DavidAM Posted September 9, 2010 Share Posted September 9, 2010 Look through you code for other references to $kennels_table it is getting clobbered somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/212911-insert-ignore-into-error/#findComment-1109169 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.