473,408 Members | 2,813 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,408 software developers and data experts.

How To Retrieve Data After Login

3
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include("config.php");
  3.  
  4. $name= $_POST['name'];
  5. $password= $_POST['password'];
  6.  
  7. $query = mysql_query("SELECT * FROM data WHERE name='$name', password='$password' ");
  8. if(mysql_num_rows($query))
  9. {
  10. WHILE ($rows = mysql_fetch_array($query)):
  11. echo "<center>";
  12. $name = $rows['name'];
  13. $password = $rows['password'];
  14. $age = $rows['age'];
  15. $email = $rows['email'];
  16. $contact = $rows['contact'];
  17. $address = $rows['address'];
  18. $course = $rows['course'];
  19. $education = $rows['education'];
  20. echo "$name<br>$password<br>$age<br>$email<br>$contact<br>$address<br>$course<br>$education<br>";
  21. echo "</center>";
  22. endwhile;
  23. else {
  24. echo"Error!!";
  25. }
  26. ?>
This code only shows the Error (which i have given in the echo statement).. I really don't know where is the problem in this code.. I will be very glad if anyone can help me in this.. pls
Dec 21 '15 #1
2 1124
Claus Mygind
571 512MB
I will point out your errors below, but first.
1. When posting question use the [CODE/] around your code it makes it easier for other people to read your code.

2. Use indents in your code also to make it easier to read. People are less likely to help if they cannot easily read your code.

3. You should stop using mysql and switch to either mysqli or pdo. To change this you need to enable these modules in your php.ini file. That is found where ever you installed your php. They are discontinuing the use of the old mysql.

Now to your specific errors

You have four errors.
1. In creating your query string, you do did not properly format the string. When you join your variables with your literal string, you must use the . to connect the components. Also when you have multiple items in your "where" clause you must join them with and or or, not a comma

2. In the if condition you need to capture the result of the query

3. In the while condition you need to refer to the result not the query when retrieving your data.

4. In your final output string again you failed to concatenate the string using the . between variables and literal strings.

Take a look at the changes I made below. Click the "expand" to view the code properly. In each case I left (but commented out) your original code. Then I inserted the corrected code below.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.    include("config.php");
  3.  
  4.    $name= $_POST['name'];
  5.    $password= $_POST['password'];
  6.  
  7. //your incorrect code
  8. //   $query = mysql_query("SELECT * FROM data WHERE name='$name', password='$password' ");
  9.  
  10.    $query = mysql_query("SELECT * FROM data WHERE name=".$name." and password=".$password);
  11.  
  12.  
  13. // your incorrect code
  14. //   if(mysql_num_rows($query))
  15.    if($result = mysql_num_rows($query))
  16.    {
  17.  
  18. //your incorrect code
  19. //      WHILE ($rows = mysql_fetch_array($query)):
  20.       WHILE ($rows = mysql_fetch_array($result)):
  21.         echo "<center>";
  22.         $name = $rows['name'];
  23.         $password = $rows['password'];
  24.         $age = $rows['age'];
  25.         $email = $rows['email'];
  26.         $contact = $rows['contact'];
  27.         $address = $rows['address'];
  28.         $course = $rows['course'];
  29.         $education = $rows['education'];
  30.  
  31. //your incorrect code
  32.  //       echo "$name<br>$password<br>$age<br>$email<br>$contact< br>$address<br>$course<br>$education<br>";
  33.  
  34.         echo $name."<br>".$password."<br>".$age."<br>".$email."<br>".$contact."<br>".$address."<br>".$course."<br>".$education."<br>";
  35.  
  36.         echo "</center>";
  37.  
  38.      endwhile;
  39.  
  40.   }else{
  41.  
  42.     echo"Error!!";
  43.   }
  44. ?>
  45.  
Dec 21 '15 #2
Diksha
3
Thanks for Your Help!!
Dec 22 '15 #3

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

Similar topics

0
by: Miki | last post by:
Hi. I have a IIS server with php3 installed. I have SQL server database and data stored in unicode format (nvarchar fields). In header of my php I have the meta: <meta HTTP-EQUIV="content-type"...
4
by: Claudia Fong | last post by:
Hi, I have a form where I need to display the data of a department that stores in a access db. When I first load the form it will call a function name loaddata which will get the first...
1
by: funcSter | last post by:
I want to retrieve data from an Excel file like how I would with a database. I understand that I would have to use OLE DB. Somehow I think I cannot get the connection string right, as the bit of...
5
by: ggk517 | last post by:
We are trying to develop an Engineering application using PHP, Javascript with Informix as the back-end. Is it possible to retrieve data using Javascript but by accessing the Database. Say...
3
by: karthigaj | last post by:
Hi, Happy new Year... i need to retrieve the data from the web server which is developed using HTML and i need to process those data in c but i should not use any CGIs. Can anybody help me...
1
by: gudipati | last post by:
hi,i have one problem.actually we can retrieve data from access. what is my requirement is when i retrieve data from access i want to store in text areas. finely,we can store if they r textboxes...
12
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I am a newbie to Struts and JSP...I have been working on the code below for 5 hours now..I googled a lot but couldn't get much help so finally I am here.. Hoping of getting my problem solved. Please...
0
by: lenniekuah | last post by:
Hi Friends, I need your help. Please help me. I am trying to retrieve data from Excel Spreadsheet to fill the DataGridView for display prior to updating SQL SERVER with individual DataGridView...
0
by: lenniekuah | last post by:
Hullo Good Guys, I need your help. Please help me. I am very surprise of this error message: Index was out of range. Must be non-negative and less thatnt he size of the collection. Parameter name...
1
by: mrijet | last post by:
Hi, can anyone guide me on retrieve data on ms access using c#? I just want read a specific data such as 1 table got many column So I just want to retrieve 1 row of the data using c# code..can...
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?
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.