Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Problem with login form

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Problem with login form

Postby 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]-->
    <head>
        <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" />
    </head>
    <body>
        <div class="container">
            <!-- Codrops top bar -->
            <div class="codrops-top">
              <div class="clr"></div>
            </div><!--/ Codrops top bar -->
            <header>
                <h1>Login and Registration Form</h1>
 
          </header>
            <section>            
                <div id="container_demo" >
                    <!-- hidden anchor to stop jump http://www.css3create.com/Astuce-Empecher-le-scroll-avec-l-utilisation-de-target#wrap4  -->
                    <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>
                                <p>
                                    <label for="username" class="uname" data-icon="u" > Your email or username </label>
                                    <td bgcolor="#FFFFFF"><input type="text" name="username" id="username" /></td>
                                </p>
                                <p>
                                    <label for="password" class="youpasswd" data-icon="p"> Your password </label>
                                    <td bgcolor="#FFFFFF"><input type="password" name="password" id="password" /></td>
                                </p>
                                <p class="keeplogin">
                           <input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" />
                           <label for="loginkeeping">Keep me logged in</label>
                        </p>
                                <p class="login button">
                                    <input type="submit" value="Login" />
                        </p>
                                <p class="change_link">
                           Not a member yet ?
                           <a href="#toregister" class="to_register">Join us</a>
                        </p>
                            </form>
                        </div>

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



check_login.php

Code: Select all
<?php
include('conn.php');

session_start();
$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";
   </script>
   <?php
   }
 
else
  $count = 0;
{?>
   <script type="application/javascript">
   alert("Please try again");
   window.location = "index.php";
   </script>
<?php }?>
syntaxerror286
New php-forum User
New php-forum User
 
Posts: 7
Joined: Wed Apr 11, 2012 11:50 pm

Re: Problem with login form

Postby 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.
User avatar
simplypixie
php-forum Active User
php-forum Active User
 
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron