connectivty error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yasir_memon
Forum Commoner
Posts: 48
Joined: Tue Aug 11, 2009 12:29 am

connectivty error

Post by yasir_memon »

i am using oracle database with odbc connection but it runs only else condition either i give right user name and password kindly check this coding and tell me what kind is mistake i am doing
thanks in advance


<?php
$A=$_POST["text1"];
$B=$_POST["text2"];

$conn=odbc_connect('AKTMAPP','ERP_TEST','ERP_TEST');
$sql="SELECT * FROM USERS WHERE USR_NAME='$A' and PASSWORD='$B'";
$rs=odbc_exec($conn,$sql);


if(odbc_fetch_row($rs)>0)
{
header("Location: http://index.php");
}
else
{
echo "error";
}
odbc_close($conn);
?>
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: connectivty error

Post by jackpf »

Try putting "or odbc_errormsg()" after connections and queries. Also, turn error reporting on full.
yasir_memon
Forum Commoner
Posts: 48
Joined: Tue Aug 11, 2009 12:29 am

Re: connectivty error

Post by yasir_memon »

i think there is no any connection error because when i am reteving record form table it shows be select statement , i think there is any error in logic so kindly tell me what is this i am using this on login page og my project??
thanks
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: connectivty error

Post by jackpf »

Have you got errors turned on then?

What does

Code: Select all

var_dump($conn, $rs);
display?
yasir_memon
Forum Commoner
Posts: 48
Joined: Tue Aug 11, 2009 12:29 am

Re: connectivty error

Post by yasir_memon »

there is no any error message just else condition is runing "error" is printed.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: connectivty error

Post by jackpf »

What does the code I posted display?
yasir_memon
Forum Commoner
Posts: 48
Joined: Tue Aug 11, 2009 12:29 am

Re: connectivty error

Post by yasir_memon »

it shows this message

resource(2) of type (odbc link) resource(3) of type (odbc result)
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: connectivty error

Post by jackpf »

Oh right, well you do have a connection then.

Wait, don't you mean odbc_num_rows() instead of odbc_fetch_row()?
yasir_memon
Forum Commoner
Posts: 48
Joined: Tue Aug 11, 2009 12:29 am

Re: connectivty error

Post by yasir_memon »

now i am using this code but still else condition is runing.

<?php
$A=$_POST["text1"];
$B=$_POST["text2"];

$conn=odbc_connect('AKTMAPP','ERP_TEST','ERP_TEST');
$sql="SELECT * FROM USERS WHERE USR_NAME='$A' and PASSWORD='$B'";
$rs=odbc_exec($conn,$sql);

if (!$rs)
{
exit("Error in SQL");
}

if(odbc_num_rows($rs)>0)
{
header("Location: http://index.php");
}
else
{
echo "error";
}
odbc_close($conn);
?>
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: connectivty error

Post by jackpf »

What does

Code: Select all

var_dump(odbc_num_rows($rs));
display?

Your query must just be returning no rows...are you sure the username and password you're entering exists?
yasir_memon
Forum Commoner
Posts: 48
Joined: Tue Aug 11, 2009 12:29 am

Re: connectivty error

Post by yasir_memon »

it displays

int(-1)

yes user name and password is there
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: connectivty error

Post by jackpf »

Hmm, well the php manual says that odbc_num_rows returns -1 on an error.

Hmm....
What does

Code: Select all

var_dump(odbc_fetch_rows($rs));
show?

Sorry for all the var_dump()s....but since I can't run the code myself, I can't see what it's returning :)
yasir_memon
Forum Commoner
Posts: 48
Joined: Tue Aug 11, 2009 12:29 am

Re: connectivty error

Post by yasir_memon »

its ok dear now it displys

Fatal error: Call to undefined function odbc_fetch_rows() in C:\wamp\www\RMS\login.php on line 109
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: connectivty error

Post by jackpf »

My bad, I meant odbc_fetch_row() :P

Sorry.

I'm used to mysql...
Post Reply