autocode function error
Posted: Tue May 19, 2009 11:58 pm
Hi...
I try to implement this code below to build a function that will get me an autocode such as :SM001,SM002,SM003, and so on, for my textbox, but when i run my script i've got tons of list of warning and errors, i'm using php 5, and microsoft sql server, this is my code:
could anybody tell me where i've done wrong??
this is the error message:
I try to implement this code below to build a function that will get me an autocode such as :SM001,SM002,SM003, and so on, for my textbox, but when i run my script i've got tons of list of warning and errors, i'm using php 5, and microsoft sql server, this is my code:
Code: Select all
function kdauto($tabel, $inisial){
$conn_kd = odbc_connect("server","usroffc","password");
$sql_kd = ("SELECT * FROM $tabel");
$struktur = odbc_exec($conn_kd,$sql_kd);
$field = odbc_field_name($struktur,0);
$panjang = odbc_field_len($struktur,0);
$conn_lib = odbc_connect("server","usroffc","password");
$sql_lib = ("SELECT max(".$field.") FROM ".$tabel);
$qry_lib = odbc_exec($conn_lib,$sql_lib);
$row = odbc_fetch_array($qry_lib);
if ($row[0] =="") {
$angka=0;
}
else {
$angka = substr($row[0], strlen($inisial));
}
$angka++;
$angka = strval($angka);
$tmp = "";
for($i=1; $i<=($panjang-strlen($inisial) - strlen($angka)); $i++) {
$tmp=$tmp."0";
}
return $inisial.$tmp.$angka;
}
this is the error message:
<br /><b>Warning</b>: odbc_field_name() [<a href='function.odbc-field-name'>function.odbc-field-name</a>]: Field numbering starts at 1 in <b>C:\xampp\htdocs\TokoBuku\inc.librari.php</b> on line <b>6</b><br />
<br /><b>Warning</b>: odbc_field_len() [<a href='function.odbc-field-len'>function.odbc-field-len</a>]: Field numbering starts at 1 in <b>C:\xampp\htdocs\TokoBuku\inc.librari.php</b> on line <b>7</b><br /><br /><b>Warning</b>: odbc_exec() [<a href='function.odbc-exec'>function.odbc-exec</a>]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]The max function requires 1 arguments., SQL state 37000 in SQLExecDirect in <b>C:\xampp\htdocs\TokoBuku\inc.librari.php</b> on line <b>11</b><br /><br /><b>Warning</b>: odbc_fetch_array(): supplied argument is not a valid ODBC result resource in <b>C:\xampp\htdocs\TokoBuku\inc.librari.php</b> on line <b>12</b><br />SM1