Page 1 of 1

insert ... select ... multiple cols

Posted: Sun Jan 18, 2004 7:16 pm
by glennn3
you can probably guess from this what i'm tryin' to do...

Code: Select all

INSERT  INTO titles( recID, title ) 
VALUES (   'SELECT recID
FROM user
WHERE username = glennn', '$file_name' );
do i just need to do this:

Code: Select all

$query="insert into titles (recID) select recID from user where username='$username' ";
$query1="insert into titles (title) values ('$file_name');
and is there a way to combine two queries like that...?

thanks
g

Posted: Sun Jan 18, 2004 9:12 pm
by DuFF

Code: Select all

$query="insert into titles (recID) select recID from user where username='$username' ";
I'm pretty sure that you cannot insert and select in the same statement. The only real logical option would be to:

Code: Select all

<?php
// select recID
$query = "SELECT recID FROM user WHERE username='$username'";

// insert
$query1="INSERT INTO titles (title, recID) VALUES ('$file_name', '$recID'); 
?>
This may not be what you are trying to accomplish, because I see no point in selecting the recID and then re-inserting it . . .