Page 1 of 4 1234 LastLast
Results 1 to 10 of 35
  1. #1
    Join Date
    Dec 2004
    Location
    UK
    Posts
    534
    Tokens
    141

    Default A little coding question

    Ok, my knowledge of mysql has its limits, so can anyone write the small piece of code which i put in to make it display the username when followed through...

    <?php
    if(@file_exists("installer.php"))
    {
    header("Location: installer.php?stage=1");
    }
    session_start();
    include("includes/functions.php");
    include("includes/config.php");

    // Check for login
    if($_GET['inside'] == "yes" || isset($_SESSION['username']) && isset($_SESSION['password']) && !$_SESSION['level'] == "banned") {
    ##### CHECK FOR FIRST-TIME USER #####
    $checker = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username = '$_SESSION[username]'"));

    if($checker['firsttime'] == "") {
    header('location: miniprofile.php?firstime=yes');
    die();
    } else {
    header('location: miniprofile.php?name=VALUE PUT IN USERNAME FIELD');
    die();
    }
    }


    elseif($_GET['method'] == "login") {

    $username = $_POST['username'];
    $password = $_POST['password'];

    if(empty($username) || empty($password)) {
    header('location: minilogin.php?error=2');
    die();
    }




    // Clean out and encrypt strings

    $username = clean($username);
    $password = encrypt($password);

    // We have encrypted and cleaned the strings.

    $check = mysql_query("SELECT * FROM users WHERE username = '$username'");
    while($rows = mysql_fetch_array($check)) {
    $realpass = $rows[password];
    $level = $rows[level];
    $realuser = $rows[username];
    }

    $rows3 = mysql_num_rows($check);


    if($rows3 == "0") {
    header('location: minilogin.php?error=1');
    die();
    }

    if($password == $realpass) {
    // Set the sessions
    $_SESSION['username'] = $realuser;
    $_SESSION['password'] = $password;
    $_SESSION['level'] = $level;

    ##### CHECK FOR FIRST-TIME USER #####
    $checker = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username = '$_SESSION[username]'"));

    if($checker['firsttime'] == "") {
    header('location: miniprofile.php?firstime=yes');
    die();
    } elseif($_SESSION[level] == "banned") {
    header('location: minilogin.php?banned=true');
    } else {
    header('location: minilogin.php?inside=yes');
    die();
    }
    }
    else {
    session_destroy();
    header('location: minilogin.php?error=1');
    die();
    }



    }
    ?>
    <?
    if(isset($_SESSION['username']) && isset($_SESSION['password']) && isset($_SESSION['level'])) {
    header('location: miniprofile.php');
    die();
    }
    ?>

    <link href="../default.css" rel="stylesheet" type="text/css" />

    <center>
    <form method="post" action="?method=login">
    <br>Username:<br />
    <input name="username" type="text" id="username" onChange="check(this.value)" /><div id="results"></div>

    <br />
    Password:<br />
    <label>
    <input name="password" type="password" id="password" />
    </label>
    <br />
    <br />
    <label>
    <input type="submit" name="Submit" value="Login" />
    </label>
    </form>



    <?php
    if($_GET['error'] == "1") {
    echo(" </div>
    <div id=\"error\">");
    echo("<font color='#FF0000'><b>Error:</b> Invalid username and/or password<br>");
    echo(" <br></div>");
    }
    elseif($_GET['error'] == "2") {
    echo(" </div>
    <div id=\"error\">");
    echo("<font color='#FF0000'><b>Error:</b> You must fill in both fields<br>");
    echo(" <br></div>");
    }
    elseif($_GET['banned'] == "true") {
    echo(" </div>
    <div id=\"error\">");
    echo("<font color='#FF0000'><b>Error:</b> Your account is disabled or banned!<br>");
    echo(" <br></div>");
    }
    else {
    echo(" <br></div>");
    }
    ?>
    <a href="register.php" target="home">Register</a><br>
    <a href="retreivepass.php" target="home">Forgot your password?</a>

    </body>

    </html>
    Post Count: :eusa_danc 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 1000 :eusa_danc

  2. #2
    Join Date
    Dec 2007
    Location
    Toronto, Ontario, Canada
    Posts
    689
    Tokens
    0

    Default

    Erm this might work:

    PHP Code:
    <?php
    // The database connection
    include "config.php";

    // mySQL
    $sql "SELECT * FROM users";
    $select mysql_query("SELECT username FROM users");
    while (
    $display mysql_fetch_array($select)) {
    $name $display['name'];

    // The echo
    echo ("Your username is: $username");
    }
    ?>

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    534
    Tokens
    141

    Default

    thanks, but i wanted the code i posted edited in the red highlighted bit. so basically it takes the username which has been submitted, and puts it in the link if the login is successful

    i wos too vague before sorry
    Post Count: :eusa_danc 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 1000 :eusa_danc

  4. #4
    Join Date
    Jan 2007
    Location
    Wales
    Posts
    2,432
    Tokens
    141

    Latest Awards:

    Default

    <?php
    if(@file_exists("installer.php"))
    {
    header("Location: installer.php?stage=1");
    }
    session_start();
    include("includes/functions.php");
    include("includes/config.php");

    // Check for login
    if($_GET['inside'] == "yes" || isset($_SESSION['username']) && isset($_SESSION['password']) && !$_SESSION['level'] == "banned") {
    ##### CHECK FOR FIRST-TIME USER #####
    $checker = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username = '$_SESSION[username]'"));

    if($checker['firsttime'] == "") {
    header('location: miniprofile.php?firstime=yes');
    die();
    } else {
    header('location: miniprofile.php?name=$username');
    die();
    }
    }


    elseif($_GET['method'] == "login") {

    $username = $_POST['username'];
    $password = $_POST['password'];

    if(empty($username) || empty($password)) {
    header('location: minilogin.php?error=2');
    die();
    }




    // Clean out and encrypt strings

    $username = clean($username);
    $password = encrypt($password);

    // We have encrypted and cleaned the strings.

    $check = mysql_query("SELECT * FROM users WHERE username = '$username'");
    while($rows = mysql_fetch_array($check)) {
    $realpass = $rows[password];
    $level = $rows[level];
    $realuser = $rows[username];
    }

    $rows3 = mysql_num_rows($check);


    if($rows3 == "0") {
    header('location: minilogin.php?error=1');
    die();
    }

    if($password == $realpass) {
    // Set the sessions
    $_SESSION['username'] = $realuser;
    $_SESSION['password'] = $password;
    $_SESSION['level'] = $level;

    ##### CHECK FOR FIRST-TIME USER #####
    $checker = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username = '$_SESSION[username]'"));

    if($checker['firsttime'] == "") {
    header('location: miniprofile.php?firstime=yes');
    die();
    } elseif($_SESSION[level] == "banned") {
    header('location: minilogin.php?banned=true');
    } else {
    header('location: minilogin.php?inside=yes');
    die();
    }
    }
    else {
    session_destroy();
    header('location: minilogin.php?error=1');
    die();
    }



    }
    ?>
    <?
    if(isset($_SESSION['username']) && isset($_SESSION['password']) && isset($_SESSION['level'])) {
    header('location: miniprofile.php');
    die();
    }
    ?>

    <link href="../default.css" rel="stylesheet" type="text/css" />

    <center>
    <form method="post" action="?method=login">
    <br>Username:<br />
    <input name="username" type="text" id="username" onChange="check(this.value)" /><div id="results"></div>

    <br />
    Password:<br />
    <label>
    <input name="password" type="password" id="password" />
    </label>
    <br />
    <br />
    <label>
    <input type="submit" name="Submit" value="Login" />
    </label>
    </form>



    <?php
    if($_GET['error'] == "1") {
    echo(" </div>
    <div id=\"error\">");
    echo("<font color='#FF0000'><b>Error:</b> Invalid username and/or password<br>");
    echo(" <br></div>");
    }
    elseif($_GET['error'] == "2") {
    echo(" </div>
    <div id=\"error\">");
    echo("<font color='#FF0000'><b>Error:</b> You must fill in both fields<br>");
    echo(" <br></div>");
    }
    elseif($_GET['banned'] == "true") {
    echo(" </div>
    <div id=\"error\">");
    echo("<font color='#FF0000'><b>Error:</b> Your account is disabled or banned!<br>");
    echo(" <br></div>");
    }
    else {
    echo(" <br></div>");
    }
    ?>
    <a href="register.php" target="home">Register</a><br>
    <a href="retreivepass.php" target="home">Forgot your password?</a>

    </body>

    </html>
    Last edited by ThisNameWillDo!; 16-12-2007 at 02:37 PM.
    Free Online Games And Videos:
    http://www.vincesgames.com



  5. #5
    Join Date
    Dec 2004
    Location
    UK
    Posts
    534
    Tokens
    141

    Default

    dont work..
    Post Count: :eusa_danc 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 1000 :eusa_danc

  6. #6
    Join Date
    Jan 2007
    Location
    Wales
    Posts
    2,432
    Tokens
    141

    Latest Awards:

    Default

    Hi, can you tell us what the error is?

    - Vince.
    Last edited by ThisNameWillDo!; 16-12-2007 at 02:44 PM.
    Free Online Games And Videos:
    http://www.vincesgames.com



  7. #7
    Join Date
    Dec 2007
    Location
    Toronto, Ontario, Canada
    Posts
    689
    Tokens
    0

    Default

    Try this:

    PHP Code:
    <?php
    if(@file_exists("installer.php"))
    {
    header("Location: installer.php?stage=1");
    }
    session_start();
    include(
    "includes/functions.php");
    include(
    "includes/config.php");

    // Check for login
    if($_GET['inside'] == "yes" || isset($_SESSION['username']) && isset($_SESSION['password']) && !$_SESSION['level'] == "banned") {
    ##### CHECK FOR FIRST-TIME USER #####
    $checker mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username = '$_SESSION[username]'"));
    $username $_POST['username'];

    if(
    $checker['firsttime'] == "") {
    header('location: miniprofile.php?firstime=yes');
    die();
    } else {
    header('location: miniprofile.php?name=$username');
    die();
    }
    }


    elseif(
    $_GET['method'] == "login") {

    $username $_POST['username'];
    $password $_POST['password'];

    if(empty(
    $username) || empty($password)) {
    header('location: minilogin.php?error=2');
    die();
    }




    // Clean out and encrypt strings

    $username clean($username);
    $password encrypt($password);

    // We have encrypted and cleaned the strings.

    $check mysql_query("SELECT * FROM users WHERE username = '$username'");
    while(
    $rows mysql_fetch_array($check)) {
    $realpass $rows[password];
    $level $rows[level];
    $realuser $rows[username];
    }

    $rows3 mysql_num_rows($check);


    if(
    $rows3 == "0") {
    header('location: minilogin.php?error=1');
    die();
    }

    if(
    $password == $realpass) {
    // Set the sessions
    $_SESSION['username'] = $realuser;
    $_SESSION['password'] = $password;
    $_SESSION['level'] = $level;

    ##### CHECK FOR FIRST-TIME USER #####
    $checker mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username = '$_SESSION[username]'"));

    if(
    $checker['firsttime'] == "") {
    header('location: miniprofile.php?firstime=yes');
    die();
    } elseif(
    $_SESSION[level] == "banned") {
    header('location: minilogin.php?banned=true');
    } else {
    header('location: minilogin.php?inside=yes');
    die();
    }
    }
    else {
    session_destroy();
    header('location: minilogin.php?error=1');
    die();
    }



    }
    ?>
    <?
    if(isset($_SESSION['username']) && isset($_SESSION['password']) && isset($_SESSION['level'])) {
    header('location: miniprofile.php');
    die();
    }
    ?>

    <link href="../default.css" rel="stylesheet" type="text/css" />

    <center>
    <form method="post" action="?method=login">
    <br>Username:<br />
    <input name="username" type="text" id="username" onChange="check(this.value)" /><div id="results"></div>

    <br />
    Password:<br />
    <label>
    <input name="password" type="password" id="password" />
    </label>
    <br />
    <br />
    <label>
    <input type="submit" name="Submit" value="Login" />
    </label>
    </form>



    <?php
    if($_GET['error'] == "1") {
    echo(
    " </div>
    <div id=\"error\">"
    );
    echo(
    "<font color='#FF0000'><b>Error:</b> Invalid username and/or password<br>");
    echo(
    " <br></div>");
    }
    elseif(
    $_GET['error'] == "2") {
    echo(
    " </div>
    <div id=\"error\">"
    );
    echo(
    "<font color='#FF0000'><b>Error:</b> You must fill in both fields<br>");
    echo(
    " <br></div>");
    }
    elseif(
    $_GET['banned'] == "true") {
    echo(
    " </div>
    <div id=\"error\">"
    );
    echo(
    "<font color='#FF0000'><b>Error:</b> Your account is disabled or banned!<br>");
    echo(
    " <br></div>");
    }
    else {
    echo(
    " <br></div>");
    }
    ?>
    <a href="register.php" target="home">Register</a><br>
    <a href="retreivepass.php" target="home">Forgot your password?</a>

    </body>

    </html>

  8. #8
    Join Date
    Dec 2004
    Location
    UK
    Posts
    534
    Tokens
    141

    Default

    i'v tried that too.

    in the browser basically when they log in it shows miniprofile.php?name=$realuser


    a want that $realuser bit to say the username that they have just logged in with, or typed in below
    Last edited by :Lively; 16-12-2007 at 02:44 PM.
    Post Count: :eusa_danc 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 1000 :eusa_danc

  9. #9
    Join Date
    Jan 2007
    Location
    Wales
    Posts
    2,432
    Tokens
    141

    Latest Awards:

    Default

    Quote Originally Posted by loserWILL View Post
    Try this:

    PHP Code:
    <?php
    if(@file_exists("installer.php"))
    {
    header("Location: installer.php?stage=1");
    }
    session_start();
    include(
    "includes/functions.php");
    include(
    "includes/config.php");

    // Check for login
    if($_GET['inside'] == "yes" || isset($_SESSION['username']) && isset($_SESSION['password']) && !$_SESSION['level'] == "banned") {
    ##### CHECK FOR FIRST-TIME USER #####
    $checker mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username = '$_SESSION[username]'"));
    $username $_POST['username'];

    if(
    $checker['firsttime'] == "") {
    header('location: miniprofile.php?firstime=yes');
    die();
    } else {
    header('location: miniprofile.php?name=$username');
    die();
    }
    }


    elseif(
    $_GET['method'] == "login") {

    $username $_POST['username'];
    $password $_POST['password'];

    if(empty(
    $username) || empty($password)) {
    header('location: minilogin.php?error=2');
    die();
    }




    // Clean out and encrypt strings

    $username clean($username);
    $password encrypt($password);

    // We have encrypted and cleaned the strings.

    $check mysql_query("SELECT * FROM users WHERE username = '$username'");
    while(
    $rows mysql_fetch_array($check)) {
    $realpass $rows[password];
    $level $rows[level];
    $realuser $rows[username];
    }

    $rows3 mysql_num_rows($check);


    if(
    $rows3 == "0") {
    header('location: minilogin.php?error=1');
    die();
    }

    if(
    $password == $realpass) {
    // Set the sessions
    $_SESSION['username'] = $realuser;
    $_SESSION['password'] = $password;
    $_SESSION['level'] = $level;

    ##### CHECK FOR FIRST-TIME USER #####
    $checker mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username = '$_SESSION[username]'"));

    if(
    $checker['firsttime'] == "") {
    header('location: miniprofile.php?firstime=yes');
    die();
    } elseif(
    $_SESSION[level] == "banned") {
    header('location: minilogin.php?banned=true');
    } else {
    header('location: minilogin.php?inside=yes');
    die();
    }
    }
    else {
    session_destroy();
    header('location: minilogin.php?error=1');
    die();
    }



    }
    ?>
    <?
    if(isset($_SESSION['username']) && isset($_SESSION['password']) && isset($_SESSION['level'])) {
    header('location: miniprofile.php');
    die();
    }
    ?>

    <link href="../default.css" rel="stylesheet" type="text/css" />

    <center>
    <form method="post" action="?method=login">
    <br>Username:<br />
    <input name="username" type="text" id="username" onChange="check(this.value)" /><div id="results"></div>

    <br />
    Password:<br />
    <label>
    <input name="password" type="password" id="password" />
    </label>
    <br />
    <br />
    <label>
    <input type="submit" name="Submit" value="Login" />
    </label>
    </form>



    <?php
    if($_GET['error'] == "1") {
    echo(
    " </div>
    <div id=\"error\">"
    );
    echo(
    "<font color='#FF0000'><b>Error:</b> Invalid username and/or password<br>");
    echo(
    " <br></div>");
    }
    elseif(
    $_GET['error'] == "2") {
    echo(
    " </div>
    <div id=\"error\">"
    );
    echo(
    "<font color='#FF0000'><b>Error:</b> You must fill in both fields<br>");
    echo(
    " <br></div>");
    }
    elseif(
    $_GET['banned'] == "true") {
    echo(
    " </div>
    <div id=\"error\">"
    );
    echo(
    "<font color='#FF0000'><b>Error:</b> Your account is disabled or banned!<br>");
    echo(
    " <br></div>");
    }
    else {
    echo(
    " <br></div>");
    }
    ?>
    <a href="register.php" target="home">Register</a><br>
    <a href="retreivepass.php" target="home">Forgot your password?</a>

    </body>

    </html>
    That should definitely work..

    - Vince.
    Free Online Games And Videos:
    http://www.vincesgames.com



  10. #10
    Join Date
    Dec 2007
    Location
    Toronto, Ontario, Canada
    Posts
    689
    Tokens
    0

    Default

    Quote Originally Posted by :Lively View Post
    i'v tried that too.

    in the browser basically when they log in it shows miniprofile.php?name=$realuser
    Try what I posted.

Page 1 of 4 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •