eth3king February 2016

PHP - How to print errors on login form on index page?

Ok, so this question is kind of hard to word, but i'll try my best. So I currently have an index.php page with a pop-up login form and I have login.php with all the login php stuff to deal with the request. At the moment I can only seem to print login errors on the login.php page, which opens up a blank white page with just the errors on that, due to the fact that the form action on my index.php form is set to "login.php" which deals with the login stuff.. What I want is to print the erros on the login form in my index.php, but have the login.php deal with the rest of the php. I hope that kind of makes sense.

<form action="login.php" method="post">
                <label>Email Address</label>
                <input type="text" name="email"/>
                <br />

                <label>Password</label>
                <input type="password" name="password"/>
                <br />
                <!--<?php 
                    if(empty($errors)===false){
                        echo output_errors($errors);    
                    }
                ?>-->
                <div class="checkbox">
                    <input id="remember" type="checkbox" />
                    <label for="remember">Keep me signed in</label>
                </div>

                <div class="action_btns">
                    <div class="one_half last"><input type="submit" class="btn btn-blue" value="Login"></div>
                    <div class="one_half last"><a href="#" id="register_form" class="btn">Sign up</a></div>
                </div>
            </form>

Above is the code for my form on the index.php page. the commented out php in that is where I want to print the errors. Below is my login.php

    <?php
include 'init.php';


function sanitize($data){
    return mysql_real_        

Answers


Kyle E4K February 2016

A tip before I start is to never put variables that are not constant into prepared statements, you're allowing user input directly to your SQL statements.

But more to the point, if you want to receive errors, I'd suggest you use a basic die($db->error); where you want to return an error via the database.

Always remember to $db->close(); at the end of working with a connection.

Post Status

Asked in February 2016
Viewed 1,572 times
Voted 8
Answered 1 times

Search




Leave an answer