Jump to content

[SOLVED] INSERT problem


tgavin

Recommended Posts

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?
Link to comment
https://forums.phpfreaks.com/topic/35684-solved-insert-problem/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/35684-solved-insert-problem/#findComment-169139
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/35684-solved-insert-problem/#findComment-169195
Share on other sites

Archived

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

×
×
  • Create New...

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.