Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP 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 August 17th, 2005, 06:30 AM
Registered User
 
Join Date: Jun 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Not redirecting after connecting to odbc msacess

Hai..

i hav one problem.., i am trying to connect msacess database through odbc using php script; the only thing is it is fectch the data from odbc datasource(adminuser) but it is not redirecting to index.php or any other one.it is giving the error like...

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\projects\admin\index.php:7) in C:\Program Files\Apache Group\Apache2\htdocs\projects\admin\index.php on line 25

above warning giving when we enable disply_errors=on in php.ini file..

my program..

[u]index.php</u>

<?php
if ($_POST['txtusername'] != null && $_POST['txtpassword'] != '') {
    $conn = odbc_connect('admin', '', '');
    if (!$conn) {
        exit("Connection Failed: " . odbc_errormsg());
    } else
        echo "Sucessfully connected";
    $sql = "SELECT username,password FROM adminuser";
    $result = odbc_exec($conn, $sql) or die("Query failed : " . odbc_errormsg());
    echo "<br>";
    echo $result;
    if (!$result) {
        echo "Execution failed";
    } else echo "<br>";
    echo " Query execution successfull";
    echo "<br>";
    while (odbc_fetch_row($result)) {
        $line[1] = odbc_result($result, 1);
        $line[2] = odbc_result($result, 2);
        print("$line[1] $line[2]\n");
        if ($line[1] == ($_POST['txtusername']) && $line[2] == ($_POST['txtpassword'])) {
            if ($_POST['check'] == " ") {
                header("Location:hai.php");
            } else {
                header("Location:changepass.php");
            }
        }
    }
    odbc_free_result($result);
    odbc_close($conn);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Admin</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="sln.css" rel="stylesheet" type="text/css">
<script language="JavaScript">
function setfocus()
{
frm.txtpassword.focus();
}
</script>
</head>
<body onLoad="setfocus();">
<table width="100%" border="0" align="center">
  <tr> </tr>
  <tr>
    <td height="30" align="center" bgcolor="#2C6FDE"><strong>Welcome
      to Our Shop</strong></td>
  </tr>
  <tr>
    <td height="361"> <br> <form name="frm" method="post" action="" onSubmit="return validate1(frm);">
        <input type="hidden" name="flag" value="1">
        <table width="60%" height="300" border="0" align="center" cellpadding="2" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#33CC99">
          <tr>
            <td colspan="2">
              <?php if ($_POST['txtusername'] == null && $_POST['txtpassword'] == '') {
    ?>
              <div align="center" class="txtred12">Please Enter User Name And
                Password To Login Into Admin Panel.<br>
                <br>
                <br>
              </div>
              <?php
}
?>
              <?php
if ($_POST['txtusername'] != null && $_POST['txtpassword'] != '') {
    echo "<p align='center'><b>Warning ! : Please Enter Correct Username and Password.</b></p>";
}
?>
            </td>
          </tr>
          <tr>
            <td width="29%" class="txtblue11">User Name :</td>
            <td width="71%"><input name="txtusername" type="text" class="inptbx" id="Username" value="admin" readonly></td>
          </tr>
          <tr>
            <td class="txtblue11">Password :</td>
            <td><input name="txtpassword" type="password" class="inptbx" id="Password" ></td>
          </tr>
          <tr>
            <td><div align="right">
                <input type="checkbox" name="check" value="checkbox">
              </div></td>
            <td class="txtblue11">Check here to change Password</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td><div align="right"> </div></td>
            <td><input name="Submit" type="submit" class="button" value="Login">
              <input name="Submit2" type="reset" class="button" value="Clear"></td>
          </tr>
        </table>
      </form>
      <p>&nbsp;</p>
      <p>&nbsp;</p></td>
  </tr>
  <tr> </tr>
</table>
</body>
</html>

[u]hai.php</u>

<html>
<head>
<title>hai</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<em><strong>hai.........
u r a valid administrator</strong></em>
</body>
</html>


odbc data source name is "admin" and is located in c:\admin.first i created odbc datasource for that and everything is fine only problem is not redirecting..

[u]admin.mdb</u>

userid username password
   1 admin admin

it is fetching and executing but not going to next page...
plse can any one help me...

                                                     R.S.NAIDU.:)
 
Old August 17th, 2005, 02:46 PM
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


You are echoing before your redirect. You see server sends all information to client browser once; so don't send anything before you modify headers or don't modify headers after you send something.

What you need do, is rethink login of your PHP code and rewrite it, with context to what I said above.

Anyway, that's a warning message; get rid of it by ini_set(display_errors, '0'); Or use buffering ob_start(); at top and ob_end_flush(); at bottom ( this way server will buffer all o/p and then send it, at last once ).

http://www.mediasworks.com/tutorial/

http://scholarship.mediasworks.com/

Regards.








Similar Threads
Thread Thread Starter Forum Replies Last Post
ODBC - insert on a linked field - [microsoft][ODBC chimp MySQL 0 April 7th, 2005 04:44 AM
Connecting to AS400 via ODBC andrew VB.NET 2002/2003 Basics 1 January 3rd, 2005 07:43 AM
OleDb.Net vs. ODBC.Net for Connecting to Oracle cjo ASP.NET 1.0 and 1.1 Professional 3 January 13th, 2004 07:18 PM
OleDb.Net vs. ODBC.Net for Connecting to Oracle cjo ASP.NET 1.0 and 1.1 Basics 1 December 23rd, 2003 10:56 AM
Redirecting kend Classic ASP Basics 2 July 8th, 2003 04:15 AM





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