<?php
// Inkludering av databas-fil.
include("db_conn.inc");
// kolla vilket område inloggnningen ska ske i customers eller presonal.
$area=$HTTP_POST_VARS["area"];
if($area=="customer") {
$cust=$HTTP_POST_VARS["cust"];
$pwd=$HTTP_POST_VARS["pwd"];
// Fel meddelande.
$msg = htmlspecialchars("Fel kund id eller lösenord!");
// SQL-sats.
$sql="SELECT * from customers WHERE cust='$cust' AND pwd='$pwd'";
// Exekevera sql-satsen
$result=odbc_exec($conn_id,$sql);
// Om användaren ej existerar skicka vidare till loginsida!
If(!(odbc_fetch_object($result))) {
header("Location: ../frameset-filer/main.php?id=&site=customer&msg=$msg");
}
// Annars
else {
// Hämta id-nummer
$id=odbc_result($result,"CustomerID");
// Sätt kakan med id-nummer, samt en kvart på utgångs tid
setcookie("mkd_customers","$id",time()+900);
// Skicka dem vidare deras sida!
header("Location: customers.php");
}
}
if($area=="personal") {
$usr=$HTTP_POST_VARS["usr"];
$pwd=$HTTP_POST_VARS["pwd"];
// Fel meddelande.
$msg = htmlspecialchars("Fel användar id eller lösenord!");
// SQL-sats.
$sql="SELECT * from users WHERE usr='$usr' AND pwd='$pwd'";
// Exekevera sql-satsen
$result=odbc_exec($conn_id,$sql);
// Om användaren ej existerar skicka vidare till loginsida!
If(!(odbc_fetch_object($result))) {
header("Location: ../frameset-filer/main.php?id=&site=crew&msg=$msg");
}
// Annars
else {
// Hämta id-nummer
$id=odbc_result($result,"UserID");
// Sätt kakan med id-nummer!
setcookie("mkd_personal","$id",time()+900);
// Skicka dem vidare!
header("Location: personal.php");
}
}
?>
Jag har ännu inte märkt något direkt fel i denna kod, men odbc_fetch_object tycks inte fungera, men enligt PHP-manualen ska den finnas!?
Fatal error: Call to undefined function: odbc_fetch_object() in
c:\www/admin/dologin.php on line 50
This function not availible in PHP 4.1.1 , you can try this :
if (function_exists(odbc_fetch_object))
return;
function odbc_fetch_object($result, $rownumber=1) {
$rs=array();
odbc_fetch_into($result, $rownumber,$rs);
foreach ($rs as $key => $value) {
$fkey=strtolower(odbc_field_name($result, $key+1));
$rs_obj->$fkey = $value;
}
return $rs_obj;
}
if you wanna use this function in a loop you must set rownumber parameter
you can't use this function like :
while ($myobj=odbc_fetch_object($res)) {
....
}
Markus Karlsson skriver så här:
It' possible to get both odbc_fetch_object() and odbc_fetch_array() to work
just by removing #ifdef HAVE_DBMAKER/#endif in php_odbc.h line 216 (219)
and the same in php_odbc.c line 87 (90) and 1229 (1380).
I've done this sucessfully in the PHP 4.2.0 release using ODBC towards a
MySQL database.
I really can't understand why the #ifdef is there from the beginning, but
they do have their reasons.
These were the files i "patched"
/* $Id: php_odbc.c,v 1.120.2.1 2002/04/08 22:21:30 sniper Exp $ */
/* $Id: php_odbc.h,v 1.45.2.1 2002/03/12 02:27:47 sniper Exp $ */