Jump to content

MySQL & Header Re-direct URGENT HELP PLEASE!


BCAV_WEB

Recommended Posts

Hello,

 

I'm having some major major issues, with a web hosting / PHP / MySQL database issue and if anyone can help that would be amazing! Okay first I have a MySQL database setup, with a table called "staff", within that there is a "username" and "password" field pretty self explanatory. I have a login in page (login.php) see first set of coding and a loginaction (loginaction.php) and what is suppose to happen is the loginaction checks the posted data against the database and if correct relocate to another page. I have had this coding and much more complex coding working on various other servers, but this is the first time I've ever dealt with BT Business webhosting, which is pretty useless right now and poor help to date from technicians who say it is a purely a coding issue. 

 

From what I have established I believe that the issue is occuring because BT don't have the apache server setup correctly for what I'm trying to do or that the browser is seeing the "$result" on "loginaction.php" and data, resulting in a white page of  certain doom!

 

Please help!!

 

 

login.php

[<?php include "sections/phparea.php";?>

<?php include "sections/header.php";?>

<?php include "sections/left.php";?>

    <!-- start content -->

        <div id=content">

                          <?php

                              // Include the formatted error message

                              if (isset($_SESSION['message]))

                            echo

                              "<h4>".$_SESSION['message']."</h4>";

                              // Generate the login <form> layout

 

                        ?>                 

                        <form action="loginaction.php" method="post" enctype="multipart/form-data">

                        <table class="tablelogin" >

                                <tr>

                                <td>

                                    <label for="email">E-mail Address</label>                               

                                </td>

                                <td>

                                    <input type="text" name="email" id="email" />                               

                                </td>

                            </tr>

                            <tr>

                                <td>

                                    <label for="password">Password</label>                               

                                </td>

                                <td>

                                    <input type="password" name="password" id="password" />                               

                              </td>

                            </tr>

                            <tr>

                                <td> 

                                   

                                </td>

                                <td>

                                    <a href="../ambustar/accountrecovery.php">Forgotten Password?</a>   

                                </td>

                            </tr>

                            <tr>

                                <td> 

                                   

                                </td>

                                <td> 

                                   

                                </td>

                            </tr>

                            <tr>

                                <td>

                                </td>

                                <td>

                                    <input type="hidden" name="count" id="count" value="1" />

                                    <input type="reset" name="reset" id="reset" value="Clear" /> 

                                    <input type="submit" name="submit" id="submit" value="Log in" />   

                                </td>

                            </tr>

                          </table>

                        </form> 

        </div>

        <!-- end content -->

<?php include "sections/right.php";?>

<?php include "sections/footer.php";?>

 

 

                ]

loginaction.php

[<?php

    session_start();

   

    include "dbconnect.php";

   

    $email =$_POST["email"];

    $password =$_POST["password"];

    $query = "SELECT * FROM staff WHERE username = '$email' AND  password = '$password'";

    $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

    // see if any rows were returned

    if (mysql_num_rows($result) > 0)

    {

        header("Location: test.php");

    }

    else

    {

        header("Location: login.php");

    }

?>

     

]

dbconnect.php

[<?php

    $hostname = "sql5c30a.carrierzone.com";

    $username = "user";

    $password = "password";

    $databaseName = "main_bikescarsandvans_co_uk";

    $connection = mysql_connect($hostname, $username, $password);  // or die ("Unable to connect!")

    mysql_select_db($databaseName) or die ("Unable to select database!");         

?> ]

Link to comment
Share on other sites

This is the error I got

 

Warning: Cannot modify header information - headers already sent by (output started at /services3/webpages/b/i/bikescarsandvans.co.uk/public/dbconnect.php:10) in /services3/webpages/b/i/bikescarsandvans.co.uk/public/loginaction.php on line 14

Link to comment
Share on other sites

Based on where the output is being reported at by the error message and that there are not 10 lines of code in dbconnect.php, you likely have characters after the closing ?> tag in the file and they should be removed as they are content that is being output to the browser.

 

And since this is not a mysql problem, moving thread to the php help forum section...

Link to comment
Share on other sites

Resolved, as soon as I got this output I figured out what was happening via a bit ot trial and error. On the "dbconnect.php" I had both <?php and ?> when removing both I was unable to connect to the database at all, but when removing the end ?> on the "dbconnect.php" file the coding worked fine and that has allowed me to implement the more complex coding.

 

Thank you for all your help! That little bit of coding you gave me saved me from more stress, as I have been looking / dealing with this error for a couple of days now. I'm in a good mood now, with 15 minutes until my weekend offically starts!!

 

:D :D :D :D :D :D :D

Link to comment
Share on other sites

Using output buffering, in most cases is just a lazy way of masking a problem instead of actually fixing it.

 

And it adds more processing/overhead to each page and more importantly consumes memory that could push a large program over the limit of available memory.

 

It also delays the output of the HTML to the browser, so the browser must wait to start rendering a page when it could already be processing elements on the page.

 

You should only use output buffering if you want to buffer output, not to mask errors (it will also mask php error messages that are output to the browser when you then do a redirect, so it also hinders troubleshooting.)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.