Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.