By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,674 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

If condition doesn't work with ODBC

P: 15
[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
Share this Question
Share on Google+
5 Replies


ronverdonk
Expert 2.5K+
P: 4,258
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

P: 15
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
Expert 2.5K+
P: 4,258
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

P: 15
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

P: 15
Hi Guys,

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

Post your reply

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