Not redirecting when connecting to odbc msaccess

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sairaju_naidu2002
Forum Newbie
Posts: 1
Joined: Wed Aug 17, 2005 6:47 am
Contact:

Not redirecting when connecting to odbc msaccess

Post by sairaju_naidu2002 »

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..

index.php

Code: Select all

<?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"><font color="#FFFFFF" size="4" face="Verdana, Arial, Helvetica, sans-serif"><strong>Welcome
      to Our Shop</strong></font></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'><font color='red' size='3'><b>Warning ! : Please Enter Correct Username and Password.</b></font></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>

hai.php

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

<body>
<em><strong><font size="6" face="Verdana, Arial, Helvetica, sans-serif">hai......... 
u r a valid administrator</font></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..

admin.mdb

Code: Select all

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.



feyd | pls can you use

Code: Select all

tags?![/i] [/color]
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

perdy please use the

Code: Select all

tags when posting code, nobody is going to look at your code without them.

your problem - you are outputting information to the browser before you send the headers so take a look at this post to find out how to fix this ->

[url]http://forums.devnetwork.net/viewtopic.php?t=1157[/url]

alternativly you can put ob_start(); at the top of your page but that is not a recommended solution becuase you are hidding the actual problem
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

sairaju_naidu2002, in the future, try to avoid double posting in addition to using [syntax=php]tags when posting php code. Thanks.[/syntax]
Post Reply