Page 1 of 1

Want a Code to User Login Page

Posted: Fri Mar 20, 2009 8:22 am
by irsath
Hi Friends,
I am new to php and database...please help me...

To learn php and mysql I made a simple form and database ...

I want a code, Once visitor type his user name and password in login.php, If it is true , It has to go my home page. If it is false, It has to go registration page.

1- login.php

Code: Select all

 <div id="form_01">
    <table border="1px">
        <form method="POST" action="login_control.php">
            <tr>
                <td><b>User Name</b></td>
                <td><input type="text" name="uname" /></td>
            </tr>
            <tr>
                <td><b>Password</b></td>
                <td><input type="password" name="paswd" /></td>
            </tr>
            <tr>
                <td><center><input type="submit" name="login" value="Log In" /></center></td>
            </tr>
        </form>
    </table>
2- connection.php

Code: Select all

<?php
//connect with mysql
mysql_connect('localhost','root', '') or
    die(mysql_error());
    
//Creat a Main Database for our record
 
$creat= mysql_query('CREATE DATABASE IF NOT EXISTS Project_1') or
    die('could not create database');
    
//Select the database
mysql_select_db('Project_1') or
    die(mysql_error());
 
//Creat a table for our record
 
$create = 'CREATE TABLE User (
            Name    char(40)    NULL,
            User_Name   char(40)    NULL,
            Password    char(15)    NULL,
            Country     char(40)    NULL,
            PRIMARY KEY (User_Name)
            )';
            
$resul = mysql_query($create) or 
    die(mysql_error());
 
?>

Re: Want a Code to User Login Page

Posted: Fri Mar 20, 2009 9:27 am
by skacc
Hi,

I think you should start with a little more basic things. If english is your first language then you can find plenty of good tutorials on the net for PHP and MYSQL.

But to answer your question:
There is a problem with the 'connection.php'. Every time you run that script it will try to create a database and a table. That file should be used only to connect to the database, then finish:
like this:

Code: Select all

//connect with mysql
mysql_connect('localhost','root', '') or
die(mysql_error());
 
//Select the database
mysql_select_db('Project_1') or
die(mysql_error());
And it should end there. Call that on the top of every page which uses database.

About creating the database and the table in it, you just need ot do that once using phpmyadmin for example: Get phpmyadmin from here

in the login_control.php include connection.php on the top, then you can get the variables from the submitted form like this:

Code: Select all

 
$_POST['uname'] // the username which was entered
$_POST['paswd'] // the password which was entered
 
Then you can check in the database with a query if there is an entry in your table called 'User' where Username and Password is the same with the entered information.

Re: Want a Code to User Login Page

Posted: Fri Mar 20, 2009 9:38 am
by irsath
Yes, I am new to php...

IF you don'd mind, can you provide me any links to learn about that ???

Re: Want a Code to User Login Page

Posted: Fri Mar 20, 2009 2:13 pm
by skacc
Sure,

This one seems to be for beginners: http://devzone.zend.com/node/view/id/627
But you can check out any of these, see which one is better for you: http://www.google.com/search?hl=en&q=le ... h&aq=f&oq=

You should have a few things on your computer to can develop properly. This article helps you get them and install them (everything is free) http://www.wikihow.com/Install-Apache,- ... Windows-PC

Good luck,
Skacc