473,378 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

If condition doesn't work with ODBC

[PHP]<?
include ("dbconn.php");
$userid = $_POST['userid'];
$password = $_POST['password'];
$select = "SELECT * FROM plus_signup WHERE userid='$userid' AND password = '$password'";
echo "Select : $select"; //I get the above Qurey executed here....

$result = odbc_exec($conn,$select);

if($rec=odbc_fetch_array($result))//records found....Check if userid and password matches.
{
echo "output something...!";// this value gets printed.

//After this, there is no exection at all...........


if(($rec['userid']==$userid)&&($rec['password']==$password))
{
$deptid = $rec['deptid'];
echo "deptid".$deptid;
exit();
include "include/newsession.php";
echo "<p class=data> <center>Successfully,Logged in<br><br><a href='logout.php'> Log OUT </a><br><br><a href=welcome.php>Click here if your browser is not redirecting automatically or you don't want to wait.</a><br></center>";
print "<script>";
print " self.location='welcome.php';"; // Comment this line if you don't want to redirect
print "</script>";
}
}

else {
session_unset();
echo "<font face='Verdana' size='2' color=red>Wrong Login. Use your correct Userid and Password and Try <br><center><input type='button' value='Retry' onClick='history.go(-1)'></center>";
}

//include ("footer.php");
?>[/PHP]

Iam using 2 if conditions in php MSSQL and i get no result for the second if...Any idea?
You can see my comments of what is the output i get.

Thanks....
Feb 15 '07 #1
5 1646
ronverdonk
4,258 Expert 4TB
What makes you think that the second if condition is definitely true? Meaning that, when it is NOT true, your script ends without any further processing.

In order to get nearer to the problem, display an error or something in the else branch, then you know at least that your script continues. Like this

[php] if(($rec['userid']==$userid)&&($rec['password']==$password))
{
$deptid = $rec['deptid'];
echo "deptid".$deptid;
exit();
include "include/newsession.php";
echo "<p class=data> <center>Successfully,Logged in<br><br><a href='logout.php'> Log OUT </a><br><br><a href=welcome.php>Click here if your browser is not redirecting automatically or you don't want to wait.</a><br></center>";
print "<script>";
print " self.location='welcome.php';"; // Comment this line if you don't want to redirect
print "</script>";
}
else {
print "Record does not match!";
}
}
[/php]

Ronald :cool:
Feb 16 '07 #2
Hi Ronald,
I have tried with your code but still it is the same...
Anyway i have jsut tried one simple code mentioned below but no result.
[PHP]<?
$conn = odbc_connect('Billing-1','Admin','y6NDQK8fy^io@ou');
$userid = $_POST['userid'];
$password = $_POST['password'];
$select = "SELECT * FROM plus_signup WHERE userid='$userid' AND password = '$password'";
echo "Select : $select";
$result = odbc_exec($conn, $select);
while ($row = odbc_fetch_array($result))
{
$rowid = $row['userid'];
$pwd = $row['password'];
}
echo "Row id :".$rowid;
echo "password : ".$pwd;
?>[/PHP]
i get this result
Select : SELECT * FROM plus_signup WHERE userid='imran' AND password = 'khan'
Row id :
password :
Feb 16 '07 #3
ronverdonk
4,258 Expert 4TB
But you must always test the result of a query, such as:

[php]$result = odbc_exec($conn, $select);
if ($result) {
$no=odbc_num_rows($result);
if ($no > 0) {
while ($row = odbc_fetch_array($result)) {
$rowid = $row['userid'];
$pwd = $row['password'];
}
echo "Row id :".$rowid;
echo "password : ".$pwd;
}
else {
echo 'No results in query";
}
}
else
echo "Query error!";
?>[/php]

If this doesn't work, there is still another (bit far-fetched) reason could be that you do not have the correct driver installed.

Ronald :cool:
Feb 16 '07 #4
I have the drivers properly installed>
when i Just tried with only one condition in where statement it works.
i.e.
[PHP]<?
$conn = odbc_connect('server-1','user','password');
$userid = $_POST['userid'];
$password = $_POST['password'];
//echo $userid;
//echo $password;
$select = "SELECT * FROM plus_signup where userid = '$userid' ";
echo "Select : $select";
$result = odbc_exec($conn, $select);
while ($row = odbc_fetch_array($result))
{
//write out all the rows from the table
echo "<br>".$row['userid'];
echo "<br>".$row['password'] . '<br/>';
}
?> [/PHP]
I get the below output
[PHP]Select : SELECT * FROM plus_signup where userid = 'tester'
tester
testing
[/PHP]

Please suggest if my query is wrong
Feb 17 '07 #5
Hi Guys,

Finally I could able to get connected and retrive records.. Its working now.
Thanks for the precious help.
Feb 17 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Colin Colin | last post by:
We migrated our intranet site from IIS4 NT4 (\\GHCNT8) to a Windows 2003 server with IIS6 (\\NT58) using the IIS Migration Tools. I have a few ASP pages that access Foxpro data on a different...
9
by: hemal | last post by:
I came across a very strange situation at work. There is an order of magnitude difference in execution time for the following two queries (10 v/s ~130 msec): select count(*) from table_name...
1
by: loRdK | last post by:
Hi, I have a database stored in MS SQL 2000 and an application written in VB5, which connects the database via JET/ODBC. I have a problem with the UNION statement.
3
by: kakaz | last post by:
Hi All there! I am quite new in MS SQL administration so let me explain how it work on Your instances of SQL Servers. We have several DTS packages on our server, all of them managed on some...
24
by: Benjamin Doyle | last post by:
In Chip Irek's "A PRIMER ON USING DB2 WITH .NET" (www.15seconds.com), he states that "...ODBC doesn't support DB2 stored procedures. So if you are building an application heavily dependant on...
8
by: John Welch | last post by:
I have a command button with the following code: DoCmd.OpenForm "frmSearchAssignments", , , "SearchAssignmentID = 1" (SearchAssignmentID is the PK, auto number) When it runs, the form opens but...
0
by: Rob R. Ainscough | last post by:
I'm pretty frustrated right now, but I'm unable to get a Launch Condition to work at all in my Condition statement of a Registry entry. (working on a Deployment Project) 1. In Launch...
6
by: Bob | last post by:
I'm not sure why this doesn't work... EACRank: IIf(>20,"1",IIf(<14.99,"3",IIf((>14.99) And (<19.99),"2"))) The first condition returns a 1 as desired. The second condition returns a 3 The...
0
by: sudhaoncyberworld | last post by:
Dear Techies, I do have small issue on connecting oracle server from .net This is the code snippet public string strConString = "Driver={Microsoft ODBC for...
7
by: Gary | last post by:
Hello guys! Bear with me, I am a newbie. She is the Data Warehouse manager. She has about 50 users to use the Oracle database from M$ Access via ODBC connection. All those users have only...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.