Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 3rd, 2005, 04:36 AM
Registered User
 
Join Date: Jun 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default redirect to new page using php

Hi I'm having problems trying to redirect to another page using php. My code is pure php - no html before the script but I keep getting errors. The code is:
<?php
session_start(); // start the session

$errorMessage = '';
if (isset($_POST['userName']) && isset($_POST['pWord'])) {
   ob_start();
   include 'library/config.php';
   include 'library/opendb.php';
   $userId = $_POST['userName'];
   $password = $_POST['pWord'];
   // check if the user id and password combination exist in database
   $sql = "SELECT userId FROM auth_user WHERE userId = '$userId' AND userPWord = '$password'";
   $result = mysql_query($sql) or die('Query failed. ' . mysql_error());
    // if the user id and password match, 1 row at least will be returned
    if (mysql_num_rows($result) == 1) {
     // set the session
      $_SESSION['db_is_logged_in'] = true;
      // after login we move to the main page
       ob_end_flush();
      header('Location:http://localhost/morindacards/mainAmend.php');
//echo "we're in";
      exit;
   }
   else{
      $errorMessage = 'Sorry, wrong user id / password ';
      $echo $errorMessage;
   }
   include 'library/closedb.php';
}
?>

the errors are:

Warning: Cannot modify header information - headers already sent by (output started at c:\Inetpub\wwwroot\...

Can anyone help? This is driving me nuts.
G

 
Old June 3rd, 2005, 05:09 AM
Registered User
 
Join Date: Jun 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i've found the answer - for anyone who's looking.

insert
ob_start(); at the beginning of the script to buffer the output and
ob_clean();before you want to redirect!
It's finally working!!

 
Old June 3rd, 2005, 07:52 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

It'll be best, if you learn to write code ( rethink logic, loops, structure ) without buffering :D
http://www.mediasworks.com/literature/
 
Old June 6th, 2005, 02:59 AM
Registered User
 
Join Date: Jun 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

that's helpful anshul. Thank you very much






Similar Threads
Thread Thread Starter Forum Replies Last Post
Page redirect help jroxit Classic ASP Basics 7 August 11th, 2008 11:01 AM
Help With PHP ?=name redirect. TheSchwa Beginning PHP 4 September 12th, 2007 02:32 AM
redirect to page other than default page sarah lee ASP.NET 1.0 and 1.1 Basics 3 December 15th, 2006 05:45 PM
Redirect to new page without closing current page peter2004 ASP.NET 2.0 Basics 5 June 5th, 2006 08:49 PM
Hidden redirect but no php parsing klokkie Beginning PHP 2 August 5th, 2004 11:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.