entry data from get another table

hi , I’am newbie SC

I have a problem with SC.
on this form, i need get data from another table (kendaraan) and put this data to transaction table.
on transaction validate :

$nopol = sc_sql_injection({nomor_kendaraan});

$sql = “SELECT
depo,
divisi,
jenis,
merk,
tahun
FROM dbo.kendaraan
WHERE no_pol_baru =”.$nopol;
sc_lookup(rs, $sql);

if(count({rs}) == 0)
{
//sc_log_add(‘login Fail’, {lang_login_fail} . {login});
sc_error_message({lang_error_login});
sc_error_exit();
}
else
{
$bbm_depo = {depo};
$bbm_divisi = {divisi};
$bbm_jenis = {jenis};
$bbm_merk = {merk};
$bbm_tahun = {tahun};
}

//================================================
// WRITE TO DATABASE
//================================================
{week_bbm} = date(“W”,strtotime({tanggal}));
{month_bbm} = date(“m”,strtotime({tanggal}));
{year_bbm} = date(“Y”,strtotime({tanggal}));
{depo}=$bbm_depo;
{divisi}=$bbm_divisi;
{jenis_mobil} = $bbm_jenis;
{merk}=$bbm_merk;
{tahun_kendaraaan}= $bbm_tahun;
{rasio_bbm} = {jml_km} / {liter_bbm};

=========================

Error display :
Error
Undefined variable: jenis
Undefined variable: tahun
Error inserting:
The statement has been terminated.

View SQL as follow :

Error
Undefined variable: jenis
Undefined variable: tahun
Error inserting:
The statement has been terminated.

View SQL
INSERT INTO dbo.bbm_transaksi (tanggal, week_bbm, month_bbm, year_bbm, depo, nomor_kendaraan, divisi, jenis_mobil, driver, merk, tahun_kendaraan, km, jml_km, liter_bbm, harga_bbm, rasio_bbm) VALUES (‘11272014’, 01, 12, 1969, ‘’, ‘L 1427 OT’, ‘’, ‘’, ‘Suyanto’, ‘’, ‘’, 30000, 100, 50, 6500, 2)

From this view SQL error,

#1. i found table master cant insert to table bbm_transaction.
#2. date 11272014, i split on week, month and year is wrong ( 01, 12, 1969)

please help, how to correct this error

Regards
Iwan Setiawan

I already change script as bellow :

$nopol = sc_sql_injection({nomor_kendaraan});
$tanggalan = sc_sql_injection({tanggal});

$sql = “SELECT
depo,
divisi,
jenis,
merk,
tahun
FROM dbo.kendaraan
WHERE no_pol_baru =”.$nopol;
sc_lookup(rs, $sql);
sc_alert ($tanggalan);
if(count({rs}) == 0)
{
sc_error_message({lang_error_login});
sc_error_exit();
}
else
{
//sc_alert (count({rs}));
$bbm_depo = {rs[0][0]};
$bbm_divisi = {rs[0][1]};
$bbm_jenis = {rs[0][2]};
$bbm_merk = {rs[0][3]};
$bbm_tahun = {rs[0][4]};
}
//sc_alert (count({rs}));
//================================================
// MENULIS KE DATABASE
//================================================
{week_bbm} = date(“W”,strtotime($tanggalan));
{month_bbm} = date(“m”,strtotime($tanggalan));
{year_bbm} = date(“Y”,strtotime($tanggalan));
{depo}=$bbm_depo;
{divisi}=$bbm_divisi;
{jenis_mobil} = $bbm_jenis;
{merk}=$bbm_merk;
{tahun_kendaraaan}= $bbm_tahun;
{rasio_bbm} = {jml_km} / {liter_bbm};

=================================
now, data from another table already included. but why still error :

Error
Error inserting:
The statement has been terminated.

View SQL

INSERT INTO dbo.bbm_transaksi (tanggal, week_bbm, month_bbm, year_bbm, depo, nomor_kendaraan, divisi, jenis_mobil, driver, merk, tahun_kendaraan, km, jml_km, liter_bbm, harga_bbm, rasio_bbm) VALUES (‘11262014’, 01, 12, 1969, ‘BLITAR’, ‘L 1427 OS’, ‘OM’, ‘MOBIL PENUMPANG’, ‘bambang’, ‘DAIHATSU’, ‘’, 9, 8, 7, 6, 1.1428571428571)

Question :
#1. week, month and year still wrong
#2. Still can’t insert (save data)

we hope your suggestion

Iwan,

It would appear to me that you are trying to reference fields from your sc_lookup wrong.

If you are doing a sc_lookup(rs,$sql) to read in depo, divisi, jenis, merk, tahun from another table, then you do not reference the fields as {depo}, {divisi}, etc… You reference them as $rs[0][0], $rs[0][1], etc.

When you are referencing the fields from the grid you use the curly braces {}

Hope this helps.

Dave

thanks Dave for your guidance. now my SC it work perfectly