How to insert session data in INSERT, SELECT sql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pinkyana
    New Member
    • Apr 2010
    • 2

    #1

    How to insert session data in INSERT, SELECT sql

    Help me plzz...

    I insert data into pohonLatihan table from senarailatihan table. It done!!
    But how can i insert the 'user id' that i capture from the 'session' into the same table.?

    Code:
     $no_pekerja = $_SESSION['user_id'];
    
    $id_latihan=$_GET['id_latihan'];
    
    
    $insert_query= "INSERT INTO pohonLatihan (namalatihan, tempat, t_mula, t_tamat, spesifikasi, jum_jam)
            SELECT namalatihan,tempat,t_mula,t_tamat,spesifikasi, jum_jam 
    		FROM senarailatihan WHERE id_latihan='$id_latihan'";
  • chathura86
    New Member
    • May 2007
    • 227

    #2
    you can have the variable in the SELECT statement

    assume that you have a user_id column and you want to insert $no_pekerja to that here how it does

    [CODE=php]$insert_query= INSERT INTO pohonLatihan (namalatihan, tempat, t_mula, t_tamat, spesifikasi, jum_jam, user_id)
    SELECT namalatihan,tem pat,t_mula,t_ta mat,spesifikasi , jum_jam, '$no_pekerja'
    FROM senarailatihan WHERE id_latihan='$id _latihan'";[/CODE]

    Comment

    • pinkyana
      New Member
      • Apr 2010
      • 2

      #3
      thanks chathura86

      It works!! I'm just adjust...little bit more in coding..i'm really appreciate it!!!

      **it look like this
      Code:
       $no_pekerja = $_SESSION['user_id'];
      
      $id_latihan=$_GET['id_latihan'];
      
      
      $insert_query= "INSERT INTO pohonLatihan (namalatihan, tempat, t_mula, t_tamat, spesifikasi, jum_jam, no_pekerja )
              SELECT namalatihan,tempat,t_mula,t_tamat,spesifikasi, jum_jam,'$no_pekerja'
      		FROM senarailatihan WHERE id_latihan='$id_latihan'";

      Comment

      Working...