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

select command in mysql returns an empty row even though the entry exist in table

hai,
I created a database using the SQL command
Expand|Select|Wrap|Line Numbers
  1.  CREATE TABLE login_table2(user_name VARCHAR(32), first_name VARCHAR(32), 
  2.     last_name VARCHAR(32), password VARCHAR(64));
Then i inserted a data using the command below
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO login_table2(user_name ,first_name , last_name , password ) 
  2.     VALUES('ramya', 'ramya', 'muthu', 'India'); 
the data got inserted into the table.
Then i inserted another set of data using the command mentioned below.
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO login_table2(user_name ,first_name , last_name , password ) 
  2.     VALUES('jeyshree', 'jey', 'shree', 'India');
Again the data got inserted into the table too.
Then i gave the command below
Expand|Select|Wrap|Line Numbers
  1. SELECT user_name FROM login_table2;
The above command displayed all the user_ name in the table.
However when i gave the command below it does not fetch anything though the entry exist in the table.
Expand|Select|Wrap|Line Numbers
  1. SELECT password FROM login_table2 WHERE user_name = 'ramya';
Mention where i am going wrong.Awaiting your reply.Thanks in advance
Jul 3 '13 #1
9 5761
Rabbit
12,516 Expert Mod 8TB
Why in your fourth block of code do you use first name but in your last block of code you use user name?
Jul 3 '13 #2
sir/mam,
that was just an example to show u that commands in such syntax works.but actually i want the password for that particular user name.i edited the post again.please take a look
Jul 3 '13 #3
Rabbit
12,516 Expert Mod 8TB
And what is the result set returned for the modified query in the fourth block of code?
Jul 3 '13 #4
For the fourth block of code it returns
"ramya
jeyshree".
For the fifth block of code it returns nothing
Jul 4 '13 #5
For the fourth block of code it returns
"ramya
jeyshree".
For the fifth block of code it returns nothing
Jul 4 '13 #6
Rabbit
12,516 Expert Mod 8TB
If everything you posted is accurate, then I see no reason for the results you're seeing. I am of course assuming you posted everything exactly. Capitalization, spelling, punctuation exactly the same way you were running the code and what you saw as results.
Jul 4 '13 #7
if everything is right then y i am not able to find the user name and the respective password.if u know some other syntax please let me know
Jul 4 '13 #8
hai,
i used a different form of select command to verify user name and password.the code is shown below
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>login</title>
  4. </head>
  5. <body>
  6. <form action="" method="post">
  7. <strong>user_name: *</strong> <input type="text"  name="user_name">
  8. <strong>password: *</strong> <input type="text"  name="password">
  9.    <input type="submit" name="submit" value="Submit">
  10. </form>
  11. <?php
  12. if (isset($_POST['user_name'])) {
  13.         $user_name = htmlentities($_POST['user_name']);
  14.         echo 'The user name is ' . $user_name . '<br>';
  15.     }    
  16. if (isset($_POST['password'])) {
  17.         $password1 = htmlentities($_POST['password']);
  18.         echo 'The code is ' . $password1 . '<br>';
  19.     }
  20. $host = "localhost";
  21. $user = "root";
  22. $password = "";
  23. if (!$connection = mysql_connect($host,$user,$password))
  24. {
  25. $message = mysql_error();
  26. echo ".$message";
  27. echo"\nnot connected to server.try later";
  28. die();
  29. }
  30. else
  31. echo" connected to server";
  32. $database = "database_1";
  33. $db = mysql_select_db($database,$connection) or die ("Couldn’t select database.");
  34. if(!$db)
  35. echo"<br>fail in database connection";
  36. else
  37. echo"<br>successfully connected to database";
  38. $query = 'SELECT user_name,password
  39.         FROM login_table2';
  40. $result = mysql_query($query) or die ("duplicated user name.try some other");
  41. if(! $result )
  42. {
  43.   die('Could not get data: ' . mysql_error());
  44. }
  45.  echo '<br>';
  46. $match=1;    
  47. while($row = mysql_fetch_assoc($result))
  48. {
  49. $value1= $row['user_name']; 
  50. $value2= $row['password'];  
  51. if($value1== $user_name )
  52. {
  53.            $match=0;           
  54.            if($value2== $password1 )
  55.           {
  56.                 echo 'user name and password matches<br>';
  57.            } 
  58.          else
  59.          {
  60.                 echo 'user name matched.password mismatch<br>';
  61.          }
  62.          break;
  63. }
  64. if($match=='1')
  65. {
  66. echo 'user name not available<br>';
  67. }
  68. mysql_close($connection);
  69. ?>
  70.  
  71. </body>
  72. </html>
  73.  
When i give user name and password as 123 and 123 respectively
the code outputs"user name and password matches".However, when i give user name and password as ram and 123 respectively
the code outputs"user name not available" even though the entry exists in the table.Can u please say me where i am going wrong?Thanks for ur reply in advance.
Jul 7 '13 #9
Rabbit
12,516 Expert Mod 8TB
It most likely means that the values in the table are not what you think it is. You should output the values being returned by the query to see if the values are correct.
Jul 7 '13 #10

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

Similar topics

3
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns...
0
by: rg | last post by:
Hello, I use invisionboard on a bid web site (20 000 visitors each day) But my server has high load average. Could you help me to optimize these select command. 1) SELECT p.*,...
2
by: Kevin | last post by:
Hi All, I am new to MS SQL Server.I am using MS SQL 2000.I have a problem in creating a table by using Select command.I have table called "test" and i want to create another table with the same...
1
by: Arjen | last post by:
IE 6 does not return the value of a dynamic option list. Mozilla performs fine. How can I get the value of a choice in IE? Simple example below. Option list is filled with first element of array...
1
by: Crazy Cat | last post by:
Hi, whenever the underlying query being called by EXEC in the following has an empty result set I get the following error -- Invalid Data for 'Numeric' when EXEC returns empty row. However if I...
2
by: wajih.boukaram | last post by:
Hi I've been using asp.net for a couple of days now and i think I've gotten the hang of things I do have a problem when using HttpWebRequest: i request a page from a remote server and this...
6
by: lcottrell | last post by:
I'll start off by saying I'm not very experienced in writing SQL commands. I am familiar with vbscript though, and I can do a similar thing in that, but can't seem to get it to work in SQL. What I...
6
by: unpresedented | last post by:
I have this query (that runs on Oracle 10g database): SELECT ge.*, ge.concept AS glossarypivot FROM s_glossary_entries ge WHERE (ge.glossaryid = '161' OR ge.sourceglossaryid = '161') AND...
4
by: harshworkingsql | last post by:
Hi, I have one SQL Table with 3 columns as below Column1: ProductionDate - DateTime - Not NULL Column2: Quantity - Int - Not NULL Column3: ProductName -string - not null Now There are 5...
5
by: mike j | last post by:
Hi everyone, If anyone could help me with this problem I'd appreciate it greatly. Basically I have a simple table on my database. It is linked with a php form that I created on my site. The php...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.