tgavin Posted January 25, 2007 Share Posted January 25, 2007 Here are my queries:[code=php:0]$query1 = "CREATE TEMPORARY TABLE subscribers_temp(email VARCHAR(60)) TYPE=HEAP";$query2 = "INSERT INTO subscribers_temp(email) VALUES ('$email')";$query3 = "INSERT IGNORE subscribers(email) SELECT email FROM subscribers_temp";[/code]I want to insert default values into $query3, along with the SELECTing from the subscribers_temp tbl. Something like[code=php:0]$query = "INSERT IGNORE subscribers(id,email,date_added) VALUES ('', 'SELECT email FROM subscribers_temp', now())";[/code]How would I write that query? Quote Link to comment https://forums.phpfreaks.com/topic/35684-solved-insert-problem/ Share on other sites More sharing options...
HuggieBear Posted January 25, 2007 Share Posted January 25, 2007 Try it outside of the single quotes...[code=php:0]$query = "INSERT IGNORE subscribers(id,email,date_added) VALUES ('', SELECT email FROM subscribers_temp, now())";[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/35684-solved-insert-problem/#findComment-169071 Share on other sites More sharing options...
shoz Posted January 25, 2007 Share Posted January 25, 2007 You can also try the following.[code]INSERT IGNORE INTO subscribers(id,email,date_added) SELECT '', email, NOW() FROM subscribers_temp[/code]Keep in mind that assuming id is an auto incremented field that you can leave it out of the column list and the id will still be generated. Quote Link to comment https://forums.phpfreaks.com/topic/35684-solved-insert-problem/#findComment-169139 Share on other sites More sharing options...
tgavin Posted January 25, 2007 Author Share Posted January 25, 2007 Neither one of these will work. Maybe my mistake was not adding all required colums to my post in the query, as I was trying to keep it simple.I'm trying to take this query:[code=php:0]$query = "INSERT INTO table (id,email,date_added,subscribed,bounced,added_by) VALUES ('', '$email', now(), '1', '0', 'ad')";[/code]and merge it with this query:[code=php:0]$query = "INSERT IGNORE subscribers(email) SELECT email FROM subscribers_temp"[/code]So that I can get all email addresses from the subscribers_temp table PLUS manually add default information to the new record as well. Quote Link to comment https://forums.phpfreaks.com/topic/35684-solved-insert-problem/#findComment-169195 Share on other sites More sharing options...
shoz Posted January 25, 2007 Share Posted January 25, 2007 [code]INSERT IGNORE INTOsubscribers(id,email,date_added,subscribed,bounced,added_by)SELECT'', email, NOW(), '1', '0', 'ad'FROMsubscribers_temp[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35684-solved-insert-problem/#findComment-169203 Share on other sites More sharing options...
tgavin Posted January 25, 2007 Author Share Posted January 25, 2007 That did it!Thank you all :) Quote Link to comment https://forums.phpfreaks.com/topic/35684-solved-insert-problem/#findComment-169219 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.