Grow your CSS skills. Land your dream job.

what is wrong in these codes php, sql

  • # May 16, 2013 at 11:56 am
    # May 16, 2013 at 1:04 pm

    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

    # May 16, 2013 at 11:46 pm

    @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}]


    < ?php
    //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.';
    }
    }
    }
    }
    }


    ?>
    # May 17, 2013 at 3:05 am

    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.

    # May 17, 2013 at 3:29 am

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

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





    `login.php`

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

    # May 17, 2013 at 8:09 am

    @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)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".