INSERT INTO `images` (s_id, u_id, name, filename, filesize, uploaded)
SELECT s_id, ?, ?, ?, ?, ?
FROM servers
WHERE name = ?
I’m currently using this SQL statement when a user uploads an image to my site. The s_id field is a foreign key to the servers table, and the field u_id is a foreign key to the users table. I want to select the user id (u_id) from the users table by their username (always unique) and use it in this insert statement.
I’ve already done the part that selects the server id (s_id) but that was pretty much fluke and messing around. I’m not quite sure how to adapt this query to have two select statements?
Help is appreciated, thank you!
Try:
Then use the useriD variable in your INSERT afterwards. I’m a SQL Server user, not MySQL, but from what I read I think I got the syntax right.