Jump to content

error for mysql n php


xxreenaxx1

Recommended Posts

I was working on these three codes below, I have came across some problem, not sure what they are. Can some one help me!!

 

<?php
        error_reporting(E_ALL | E_STRICT);
        int_Set('display_error', false);

        session_start();

        if (isset($_SESSION['username'])){

        header('Location: ./')
        ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Login</title>
    </head>
    <body>
        <div></div>
        You are now logged in
        <a href="logout.php", Logout</a>
        <?php }
        else {
            ?>
        <form action="login.php" method="post">
        username:<input name="username" type="text" />
        password:<input name="password" type="password" />
        <input type="submit" />
    </form>
        <?php } ?>
        <?php echo $_SESSION['error']; unset($_SESSION['error']); ?>
        }


    </body>
</html>

 

 

 

 

 

<?php
session_start();// session starts

$db_host ='localhost';
$db_user = 'root';
$db_pass = '';
$db_db = login;


if (isset($_POST['username']))

{
//MySql connection
$db_link = mysql_connect($db_host, $db_user, $db_pass) or die('MySql connection error:'. mysql_error());
mysql_select_db($db_db) or die('MySql error: connot select table');

$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['pasword']);

//MySql Query
$result = mysql_query("SELECT * FROM users
WHERE username = '$username' and password = '$password'");

if (!result){
$_SESSION['error'] = '<span style="color: red" >Login Falied</span>';

} else{
    $row = mysql_fetch_assoc($result);
    $_SESSION['userid'] = $row['id'];
    $_SESSION['username'] = $username;
    $_SESSION['error'] = 'Login successful<br> Welcome,' .$username;


}

mysql_close($db_link);
}

?>

 

<?php
session_start();
if(isset($_GET['logout']))
    {
    $_SESSION = array();
    if($_COOKIE[sesiion_name()])
        {
        setcookies(session_name(),'',time()-4200);

        }
        session_destroy();
        header('Location: ./');


    }
?>

Link to comment
https://forums.phpfreaks.com/topic/195109-error-for-mysql-n-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.