Problem with login form

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 7
Joined: Wed Apr 11, 2012 11:50 pm

Problem with login form

Post by syntaxerror286 » Sat Dec 01, 2012 6:08 pm

Hi all, i really don't know what happen to my code. It usually shows no database selected. Can someone guide me, Tq.

index php

Code: Select all

<!DOCTYPE html>
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6 lt8"> <![endif]-->
<!--[if IE 7 ]>    <html lang="en" class="no-js ie7 lt8"> <![endif]-->
<!--[if IE 8 ]>    <html lang="en" class="no-js ie8 lt8"> <![endif]-->
<!--[if IE 9 ]>    <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
        <meta charset="UTF-8" />
        <!-- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">  -->
        <title>Login and Registration Form</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
        <meta name="description" content="Login and Registration Form with HTML5 and CSS3" />
        <meta name="keywords" content="html5, css3, form, switch, animation, :target, pseudo-class" />
        <meta name="author" content="Codrops" />
        <link rel="shortcut icon" href="../favicon.ico"> 
        <link rel="stylesheet" type="text/css" href="css/demo.css" />
        <link rel="stylesheet" type="text/css" href="css/style.css" />
		<link rel="stylesheet" type="text/css" href="css/animate-custom.css" />
        <div class="container">
            <!-- Codrops top bar -->
            <div class="codrops-top">
              <div class="clr"></div>
            </div><!--/ Codrops top bar -->
                <h1>Login and Registration Form</h1>
                <div id="container_demo" >
                    <!-- hidden anchor to stop jump  -->
                    <a class="hiddenanchor" id="toregister"></a>
                    <a class="hiddenanchor" id="tologin"></a>
                    <div id="wrapper">
                        <div id="login" class="animate form">
                            <form id="form1" method="post" action="check_login.php">
                                <h1>Log in</h1> 
                                    <label for="username" class="uname" data-icon="u" > Your email or username </label>
                                    <td bgcolor="#FFFFFF"><input type="text" name="username" id="username" /></td>
                                    <label for="password" class="youpasswd" data-icon="p"> Your password </label>
                                    <td bgcolor="#FFFFFF"><input type="password" name="password" id="password" /></td>
                                <p class="keeplogin"> 
									<input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" /> 
									<label for="loginkeeping">Keep me logged in</label>
                                <p class="login button"> 
                                    <input type="submit" value="Login" /> 
                                <p class="change_link">
									Not a member yet ?
									<a href="#toregister" class="to_register">Join us</a>

                        <div id="register" class="animate form">
                            <form  action="mysuperscript.php" autocomplete="on"> 
                                <h1> Sign up </h1> 
                                    <label for="usernamesignup" class="uname" data-icon="u">Your username</label>
                                    <input id="usernamesignup" name="usernamesignup" required="required" type="text" placeholder="mysuperusername690" />
                                    <label for="emailsignup" class="youmail" data-icon="e" > Your email</label>
                                    <input id="emailsignup" name="emailsignup" required="required" type="email" placeholder=""/> 
                                    <label for="passwordsignup" class="youpasswd" data-icon="p">Your password </label>
                                    <input id="passwordsignup" name="passwordsignup" required="required" type="password" placeholder="eg. X8df!90EO"/>
                                    <label for="passwordsignup_confirm" class="youpasswd" data-icon="p">Please confirm your password </label>
                                    <input id="passwordsignup_confirm" name="passwordsignup_confirm" required="required" type="password" placeholder="eg. X8df!90EO"/>
                                <p class="signin button"> 
									<input type="submit" value="Sign up"/> 
                                <p class="change_link">  
									Already a member ?
									<a href="#tologin" class="to_register"> Go and log in </a>


Code: Select all


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

$sql="SELECT * FROM user_login WHERE username='".$username."' AND password ='".$password."'";
$result=mysql_query($sql)or die(mysql_error());

if ($result)
  $count = mysql_num_rows($result)or die(mysql_error());
	<script type="application/javascript">
	alert("Login success");
	window.location = "sucess.php";
  $count = 0;
	<script type="application/javascript">
	alert("Please try again");
	window.location = "index.php";
<?php }?>

User avatar
php-forum Active User
php-forum Active User
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire

Re: Problem with login form

Post by simplypixie » Sun Dec 02, 2012 10:29 am

If you are getting the error that the database hasn't been selected then we need to see your database connection script as that is where the problem will be.

Post Reply

Who is online

Users browsing this forum: Baidu [Spider] and 8 guests