Jayashree venugopal Jayashree venugopal - 4 months ago 10
SQL Question

trying to insert data from another table

I have a table where user inserts data and the user id should be automatically added to the table which he is accessing.

$sql = "INSERT INTO leadinform (lead_compname,lead_add,lead_city,lead_compno,lead_cp,lead_cpd,lead_cpno,lead_cpemail,prodtype,prodmodel,value,clodate,uid) VALUES ('$leadname','$leadadd','$leadcity','$leadcompno','$leadcpname','$leadcpdesig', '$leadcpno','$leadcpmail','$prodtype', '$model','$value','$clodate') SELECT admin.uid FROM admin where admin.username = '$user_check' ";


This is the code I am using but it doesnt seem to work.

where am I wrong ?

Answer

try this

    $sql = "INSERT INTO leadinform (lead_compname,lead_add,lead_city,lead_compno,lead_cp,lead_cpd,lead_cpno,lead_cpemail,prodtype,prodmodel,value,clodate,uid) 
    VALUES ('$leadname','$leadadd','$leadcity','$leadcompno','$leadcpname','$leadcpdesig', '$leadcpno','$leadcpmail','$prodtype', '$model','$value','$clodate',(SELECT admin.uid FROM admin where admin.username = '$user_check' limit 1))  ";
Comments