logical mistake

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

logical mistake

Post by yasir_memon »

i am using this code it only show else condition message wether i am writing right user name and password so kindly help me in this regard if any one knows
thanks

<?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);
$count=odbc_num_rows($rs);
if (!$rs)
{
exit("Error in SQL");
}
if($count>0)
{
echo "good";
}
else
{
echo "invalid user";
}
odbc_close($conn);
?>
User avatar
bala_1225
Forum Commoner
Posts: 29
Joined: Tue Jul 28, 2009 3:20 am
Location: chennai,india

Re: logical mistake

Post by bala_1225 »

hi plz try this one....

$A=$_POST['text1'];
$B=$_POST['text2'];
yasir_memon
Forum Commoner
Posts: 48
Joined: Tue Aug 11, 2009 12:29 am

Re: logical mistake

Post by yasir_memon »

still same error kindly check this code atur side is it working properly there is no any connection error when i am runing selece statment it displys all the records i think there is any logical mistake so kindly check this waiting for replies.
yasir_memon
Forum Commoner
Posts: 48
Joined: Tue Aug 11, 2009 12:29 am

Re: logical mistake

Post by yasir_memon »

this code is working properly but it is not redirecting to other page it shows the warning message

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\RMS\login.php:8) in C:\wamp\www\RMS\login.php on line 105


if i replace header with echo it give me right output so kindlt tell me now why it is not redirecting to other page

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

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

if($count>0)
{
header("Location:log.html");
}
else
{
echo "invalid user name or password";
}
odbc_close($conn);
?>
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: logical mistake

Post by jackpf »

What's the entire script?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: logical mistake

Post by Ollie Saunders »

Change:

Code: Select all

$conn=odbc_connect('AKTMAPP','ERP_TEST','ERP_TEST');
to:

Code: Select all

$conn=odbc_connect('AKTMAPP','ERP_TEST','ERP_TEST') or die('Failed to connect to database. Reason: ' . odbc_errormsg());
to better understand if a connection is being created successfully.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: logical mistake

Post by Ollie Saunders »

Post Reply