Fujael
Fujael

Reputation: 35

How to insert mysql data from two source form and other table

I have a table with the following columns:

id
bid
name
text
time

The bid field is comes from another table and the rest are from a $_POST form.

Can anyone solve this?

$name$_POST['name'];

$text=$_POST['text'];

$time=date(j/F/Y);

The SQL queries:

INSERT INTO table1 (bid) SELECT bid FROM table2 WHERE id='6'

INSERT INTO table 1 
(name, text, time)
VALUES ($name, $text, $time)

I need both of these to happen in one single query.

Upvotes: 1

Views: 314

Answers (1)

Sashi Kant
Sashi Kant

Reputation: 13465

I think you need this ::

Insert into my_table (id, bid, name, text, time) values (var_id, (Select bid from table_2 where id2=var_id ), var_name, var_text, var_time)

Upvotes: 1

Related Questions