mysql - insert into using values and select from other table -


want add service second first table if keyword found in first table. also, while inserting want add other values first table.

i have query :

$sql="insert `firsttable`     (       `time`,       `content`,       `number`,       `service`     )     values     (       '$date',       '$message',       '$number',       (select   service         secondtable         keyword='$keyword'       )     );"; 

should have @ end ??

you can use literal values in select list:

 $sql = "insert `firsttable` " .         "(`time`, `content`, `number`, `service`) " .         "select '$date', '$message', '$number', service " .         "from secondtable " .         "where keyword = '$keyword'"; 

mandatory comment:
using variable replacement inside string leaves code susceptible sql-injection attacks. it's better practice use prepared statement.


Comments