Reputation: 1092
I want to insert certain values from an existing database into another. I know i can use the following, but i also want to insert other values (that don't exist in any database but are (for example) post values)
mysql_query("
INSERT INTO log (
f1,
f2,
f3,
f4
)
SELECT
a1,
a2,
a3,
a4
FROM
db
WHERE
a1 = '1'
") or die(mysql_error());
This only copies full database records, where i want to add other values. Something like
INSERT
$_POST['field1'],
a1,
a2,
$_POST['field2']
How can i achieve this?
Upvotes: 1
Views: 300
Reputation: 16202
You can use just constants in SELECT, example:
mysql_query("INSERT INTO log (f1, f2, f3, f4)
SELECT ".mysql_escape_string($_POST['field1']).",
a1, a2,
".mysql_escape_string($_POST['field2'])."
FROM
db
WHERE
a1 = '1' ") or die(mysql_error());
Upvotes: 2