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

How to use refresh and location?

I've got problem using

header('Refresh: 2; login.php');

i understand the concept behind it just that it can't work on my system.

can anyone help me solve my problem.

my error message is the following:


Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\fyp\do_login.php:60) in C:\xampp\htdocs\fyp\do_login.php on line 67
Sorry! Your username/password is incorrect.
Please try again.

You'll be redirected back to the login.


that page coding is something like this
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //Starting a session
  3. session_start();
  4.  
  5. //NOTE: START SESSION BEFORE USING require()
  6. require('db.php');
  7.  
  8. //Retrieve and password from form
  9. $uname = $_POST['username'];
  10. $pwd = MD5($_POST['pwd']);
  11.  
  12. //Connect to database server and choose database:
  13. mysql_connect(MACHINE, USER,'');
  14. mysql_select_db(DBNAME);
  15.  
  16. //Query to retrieve records from users table
  17. $sql = "select * from users where username='".$uname."' AND password='".$pwd."'";
  18.  
  19. //Executing query...storing records in $result
  20. $result = mysql_query($sql);
  21.  
  22. if(mysql_num_rows($result) == 1){ //valid user
  23.     /*test*/
  24.     //echo "Your username and password are correct.";
  25.     //Saving info in session: no need to save password, but only testing!
  26.     $_SESSION['username'] = $uname;
  27.     $_SESSION['pwd'] = $pwd; 
  28.     $_SESSION['login'] = 1;
  29.     $row = mysql_fetch_array($result);
  30.     $role = $row['admin'];
  31.     if($role ==1){
  32.         $_SESSION['role'] ="admin";
  33.     }//role =admin
  34.     else if ($role ==2){
  35.         $_SESSION['role'] ="manager";
  36.     }//role = non-admin
  37.     else{
  38.         $_SESSION['role'] ="staff";
  39.     }//role = non-admin    
  40.  
  41.     $_SESSION['userid'] = $row['userid']; 
  42.  
  43.     //Display link to index.php
  44.     echo header('location: index.php');
  45.  
  46.     } 
  47.     else {
  48.         $_SESSION['login'] = 0; 
  49.     }
  50. ?>
  51. <html>
  52. <head>
  53. <link rel="stylesheet" type="text/css" href="fyp.css" />
  54. </head>
  55. <body>
  56. <div id="header">
  57. </div>
  58.  
  59. <div id="leftcol">
  60. <?php
  61.     echo "<br><a href = login.php>Log In</a>";
  62. ?>
  63. </div> 
  64.  
  65. <div id="maincol">
  66. <?php
  67.     header('Refresh: 2; login.php');
  68.  
  69.     echo "Sorry! Your username/password is incorrect.<br>";
  70.     echo "Please try again.<br><br>";
  71.  
  72.     echo "You'll be redirected back to the login.";
  73. ?>
  74. </div>
  75. </body>
  76. </html>
Jul 25 '07 #1
1 1948
pbmods
5,821 Expert 4TB
Heya, fruityfreak.

Take a look at this thread.
Jul 25 '07 #2

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

Similar topics

7
by: kindermaxiz | last post by:
I have a php script with a form that insert data in a mysql db and when I click on submit I would like the page to refresh after the insertion, how can I do that? it's a php script that display...
43
by: dan baker | last post by:
I have a page that gets loaded with a meta-refresh hardcoded so that a few things on the page get updated. its kind of a fake chat board. anyway, what I need to do is turn off the meta-refresh once...
4
by: Andrew Alger | last post by:
ok i have two forms. Customer.aspx and Parent_Searh.aspx. There is a button on Customer.aspx that when executed runs javascript code to open up parent_search as a popup. After the user searches...
3
by: nicver | last post by:
I am working on updating a Web site with a frameset. A page opens a pop-up window in which the user uploads pictures. Once the upload is done, I would like to refresh the content of the frame which...
2
by: Raj | last post by:
Hi All, I have a problem with trying to refresh the parent window from child window in order to update data in the parent window. The sequence of events are 1) I click a button in the parent...
1
by: Helixpoint | last post by:
I have a frameset. left and main. Inside the main frame I have a IFRAME. I need to refresh the main frame when I post a form inside the IFRAME. I am trying the code below with no luck?? ...
1
by: Marco Maroni | last post by:
How to force image refresh on client browser ? Is ti possible to force the refresh of the same image (tha was changed server-side) to the client, without user press Contrl+F5 in IE ? - Marco
2
by: Jeronimo Bertran | last post by:
Hi, I have a page with a very data intensive grid which needs to be automatically refreshed constantly if a change is detected. In order to not refresh the complete page so often, I created an...
1
by: francois | last post by:
I have a ASPX form with a dropdownlist that makes a post back (to the same page of course, just a normal asp.net postback) That page also has an auto refresh javascript as it needs to refresh its...
7
by: Juan Romero | last post by:
Hey guys, please HELP I am going nuts with the datagrid control. I cannot get the damn control to refresh. I am using soap to get information from a web service. I have an XML writer output...
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...
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: 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.