473,395 Members | 1,948 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,395 software developers and data experts.

When the condition is false the statment insdie false condition is not showing.

Dear All,

I have a simple login script, when the user put the correct information the loop is working but when they put wrong informtion the loop is not working. Kindly find the below code.

The statement after if($result<0) is not working.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include("dbConfig.php");
  3. if(isset($_POST['login'])){
  4.     $userid = $_POST['userid'];
  5.     $userpassword = $_POST['password'];
  6.     $usertype = $_POST['usertype'];
  7.  
  8.     //$sql = mysql_query("SELECT * FROM logintable where UserID = '$userid'");
  9.     //if($sql){
  10.         $sql2 = mysql_query("SELECT * FROM logintable where UserID = '$userid' and UserPassword='$userpassword'");
  11.         //echo "h2i";
  12.         $result = mysql_num_rows($sql2) or die(mysql_error());
  13.         if($result<0){
  14.             echo "Sorry";
  15.             exit;
  16.         }
  17.         else{
  18.             while($row = mysql_fetch_array($sql2)){
  19.                 $usertype1 = $row['UserType'];
  20.                 $username =  $row['UserName'];
  21.                 $userlastlogin = $row['UserLastLoginDateTime'];
  22.                 $userlastip = $row['UserLastIP'];
  23.  
  24.                 echo $usertype1."-".$username."-".$userlastlogin."-".$userlastip;
  25.                 SESSION_START();
  26.                 $_SESSION['userid'] = $userid;
  27.                 $_SESSION['username'] = $username;
  28.                 echo $_SESSION['userid'];
  29.             }                                 
  30.         }
  31.     /*}
  32.     else{
  33.             echo "Sorry";
  34.     }*/
  35. }
  36. ?>
Oct 31 '09 #1
2 1917
Markus
6,050 Expert 4TB
Well, your logic head is flawed. mysql_num_rows() will return the number of affected rows, if there are any. If there are 0 affected rows... yes, you guessed it, mysql_num_rows() will return 0.

So, the problem is that you're checking for a number less than 0 (which you will never have). You want to be check if mysql_num_rows() is equal to 0.

Mark.
Oct 31 '09 #2
thanks it working now
Dec 14 '09 #3

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

Similar topics

45
by: Debashish Chakravarty | last post by:
K&R pg.66 describes two situations when using goto makes sense. Has anyone here come across situations where using goto provided the most elegant solution. --...
0
by: Zenobia | last post by:
This code, for a page control, is supposed to print a gif (for each new year, followed by the text of each year). It doesn't do that. It is just a simplified version of another control used for...
3
by: Nicola | last post by:
When using the NewMail.Body object, ! and spaces are being added into the email after the email has been sent. Has anyone else had this problem or even better a solution??
3
by: Ben R. | last post by:
In an article I was reading (http://www.ftponline.com/vsm/2005_06/magazine/columns/desktopdeveloper/), I read the following: "The ending condition of a VB.NET for loop is evaluated only once,...
4
by: joh12005 | last post by:
Hello, i posted for suggestions a little idea even if it still needs further thoughts but as i'm sure you could help :) if would like to implement some kind of Condition class which i coud...
4
by: Steve | last post by:
I have read a couple articles online, read my Jesse Liberty book but I am still confused as to just what the best practices are for using exceptions. I keep changing how I'm working with them and...
3
by: Agnes | last post by:
I use repater to show the data(invoice), the last column (download button) for the user to download the invoice copy However, if the invoice had been settled, the download must bet disable or...
2
by: Abdelrazag Abbas Ali | last post by:
Hi All, I'm Abdelrazag,I have one column which have the following values (0,1,NULL) and I wrote procedure which work fine using if condition that if user send 0 as value I will get all row where...
1
by: robin1983 | last post by:
Dear All, I got stuck in simple problem, I have a two php file one for registration form and one for to check and insert into the table. The problem is that when I get any kind error in...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.