Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End what is wrong in these codes php, sql

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #44821
    Rohithzr
    Participant
    #135308
    unasAquila
    Participant

    In your login.php anywhere where you need to send to user back add this

    $_SESSION = $errors;

    on the index.php

    $errors = $_SESSION;

    then do with the $errors what you need to show the information contained

    #135382
    Rohithzr
    Participant

    @unasAquila not working
    first of all it shows an unidentified index until and unless i declare it in connect.php
    second if i use this command then i end up opening a blank login.php page with no result whatsoever as there is no echo in login.php [there is echo in index.php but the form opens the login.php and no echo event occurs in index.php]

    well now take a look at these files

    login.php [added ur suggestion in wrong password section {and it reaches there tested}]


    //signin.php
    include 'connect.php';

    if(isset($_SESSION) && $_SESSION == true)
    {
    echo 'You are already signed in, you can sign out if you want.';

    }
    else
    {
    if($_SERVER != 'POST')
    {
    echo 'You cannot access this page dirctly. !!';
    }
    else
    {
    $errors = array();

    if(!isset($_POST))
    {
    $errors[] = 'The username field must not be empty.';
    }

    if(!isset($_POST))
    {
    $errors[] = 'The password field must not be empty.';
    }

    if(!empty($errors))
    {
    echo 'Uh-oh.. a couple of fields are not filled in correctly..

    ';
    echo '
      ';
      foreach($errors as $key => $value)
      {
      echo '
    • ' . $value . '
    • ';
      }
      echo '
    ';
    }
    else
    {
    $sql = "SELECT
    user_id,
    user_name,
    user_level
    FROM
    user
    WHERE
    user_name = '" . mysql_real_escape_string($_POST) . "'
    AND
    user_pass = '" . sha1($_POST) . "'";

    $result = mysql_query($sql);
    if(!$result)
    {

    echo 'Something went wrong while signing in. Please try again later.';
    //echo mysql_error(); //debugging purposes, uncomment when needed
    }
    else
    {
    if(mysql_num_rows($result) == 0)
    {


    $error = 'You have supplied a wrong user/password combination. Please try again.';
    $_SESSION = $error;
    }
    else
    {

    $_SESSION = true;


    while($row = mysql_fetch_assoc($result))
    {
    $_SESSION = $row;
    $_SESSION = $row;
    $_SESSION = $row;
    }

    echo 'Welcome, ' . $_SESSION . '.
    Proceed to the forum overview.';
    }
    }
    }
    }
    }


    ?>
    #135391
    unasAquila
    Participant

    try this in the same place. add the `header(‘Location:index.php’)`;

    if(mysql_num_rows($result) == 0) {
    $error = ‘You have supplied a wrong user/password combination. Please try again.’;
    $_SESSION = $error;
    header(‘Location: index.php’);
    }

    Also and im so sorry i missed it you need `session_start()` at the top of both files.

    #135394
    unasAquila
    Participant

    A scaled down version of what you are doing
    `index.php`

    session_start();
    if(isset($_SESSION)){
    $errors = $_SESSION;
    print_r($errors);
    }else{
    echo ‘no error messages yet’;
    }
    ?>


    Test




    `login.php`

    session_start();
    if(empty($_POST)) {
    $error = ‘You have supplied a wrong Information’;
    $_SESSION = $error;
    header(‘Location: index.php’);
    }
    ?>

    #135422
    Rohithzr
    Participant

    @unasAquila i dont know how to thank you for this. i was getting mad at this problem!! really great help
    thanks a lot

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.