Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

MySQL Database Login/Registration

  • 04-01-2010 10:47pm
    #1
    Closed Accounts Posts: 112 ✭✭


    Hi,
    I am doing a website builder web 2.0 project and stuck on something, I want my database to store username, email, password, title & full name. The title means the title of the website in which they are creating....

    I have created a registration form on beta.gahim.com/start which recives data (via PHP Post) from beta.gahim.com....

    The database name is: members

    Unfortunatly I am new to this so step-by-step instructions would be fantastic, thanks!


«13

Comments

  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Can you not get the hint? :rolleyes:


  • Closed Accounts Posts: 112 ✭✭gahim


    Webmonkey wrote: »
    Can you not get the hint? :rolleyes:

    The link doesn't go anywhere, it goes to a board.ie error page :rolleyes:, I need step by step instructions as I am new.... :confused:


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Here: http://www.boards.ie/vbulletin/showthread.php?t=2055787433

    No you don't need step by step instructions because nobody will give them to you. You need to go research a bit, make an attempt and then show us code or something explaining where you are getting stuck.

    How will you build such a website builder site if you cannot achieve this. You are jumping ahead of yourself I think.


  • Closed Accounts Posts: 112 ✭✭gahim


    Webmonkey wrote: »
    Here: http://www.boards.ie/vbulletin/showthread.php?t=2055787433

    No you don't need step by step instructions because nobody will give them to you. You need to go research a bit, make an attempt and then show us code or something explaining where you are getting stuck.

    How will you build such a website builder site if you cannot achieve this. You are jumping ahead of yourself I think.

    The link you sent went to another one of my threads


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Yeah and it was locked and you were told read the charter.


  • Advertisement
  • Closed Accounts Posts: 112 ✭✭gahim


    Hi,
    What's a charter, why was it closed and why did you just send me back to the previous forum can you send me to a page that can help me?


  • Registered Users, Registered Users 2 Posts: 23,212 ✭✭✭✭Tom Dunne


    gahim wrote: »
    Hi,
    What's a charter, why was it closed and why did you just send me back to the previous forum can you send me to a page that can help me?

    Ok, I think you need to understand where we are coming from here.

    The general rule on this forum is that people will not just tell you the answer straight out - you need to show us what you have done, where exactly you are having problems, and how you have attempted to fix the problem.

    This is to prevent people who never contribute to the forum from just wandering in, getting the answer they want, and never contributing to the forum again.

    So, show us what you've got. :)


  • Closed Accounts Posts: 112 ✭✭gahim


    I am completely lost, can someone give me a link to a page where it gives me easy instructions?

    Thanks


  • Registered Users, Registered Users 2 Posts: 1,181 ✭✭✭ronkmonster


    You are only supposed to ask for help here.
    Not for us to give you all the code you need to do it.

    If you don't know how to link webpage into mysql database why don't you try google it?
    Best put that website builder project on hold until you at least now how to do this.


  • Closed Accounts Posts: 112 ✭✭gahim


    I ran this command in the database

    CREATE TABLE `users` (
    `id` int(3) NOT NULL auto_increment,
    `login` varchar(8) default NULL,
    `password` varchar(8) default NULL,
    PRIMARY KEY (`id`)
    ) TYPE=MyISAM AUTO_INCREMENT=3 ;

    My login.php page has
    <?
    session_name
    ("Login");
    session_start();
    session_destroy();
    if($_GET/COLOR][COLOR=#dd0000]'login'[/COLOR][COLOR=#007700 == "failed") {
    [COLOR=blue ! important][COLOR=blue ! important]print[/COLOR] [/COLOR]$_GET/COLOR][COLOR=#dd0000]'cause'[/COLOR][COLOR=#007700;
    }
    ?>
    <form name="login" method="post" action="log.php?action=login">
    Username: <input type="text" name="username"><BR>
    Password: <input type="password" name="password"><BR>
    <input type="submit" value="Login">
    </form>


    Log.php has
    <?
    session_name
    ("MyLogin");
    session_start();
    if($_GET/COLOR][COLOR=#dd0000]'action'[/COLOR][COLOR=#007700 == "login") {
    $conn = mysql_connect("localhost","username","password"); // your MySQL connection data
    $db = mysql_select_db("members"); //put your database name in here
    $name
    = $_POST/COLOR][COLOR=#dd0000]'user'[/COLOR][COLOR=#007700;
    $q_user = mysql_query("SELECT * FROM USERS WHERE login='$name'");


    if(mysql_num_rows($q_user) == 1) {

    $query
    = mysql_query("SELECT * FROM USERS WHERE login='$name'");
    $data = mysql_fetch_array($query);
    if($_POST/COLOR][COLOR=#dd0000]'password'[/COLOR][COLOR=#007700 == $data/COLOR][COLOR=#dd0000]'password'[/COLOR][COLOR=#007700) {
    session_register("name");
    header("Location: /builder"); // success page. put the URL you want
    exit;
    } else {
    header("Location: login.php?login=failed&cause=".urlencode('Wrong Password'));
    exit;
    }
    } else {
    header("Location: login.php?login=failed&cause=".urlencode('Invalid User'));
    exit;
    }
    }

    // if the session is not registered
    if(session_is_registered("name") == false) {
    header("Location: login.php");
    }
    ?>


    To customise pages
    <?
    require("log.php");
    ?>
    Printing the user name in the screen is very easy. Just add this code:
    <? print $_SESSION/COLOR][COLOR=#dd0000]"name"[/COLOR][COLOR=#007700; ?>




    Put now what about the register, and am I doing everything right?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 515 ✭✭✭NeverSayDie


    gahim wrote: »
    I am completely lost, can someone give me a link to a page where it gives me easy instructions?

    Thanks

    No, we can't. OP, software development isn't easy, and in particular it doesn't lend itself to "here's the step by step thing you need to do to build XYZ non-trivial piece of software". Those of us who do it for a living spent a long time learning how to do it, mostly by practising it - a lot. And it doesn't get particularly easy when you've got that experience, it's still a challenging job to work at - if it wasn't, I wouldn't be this well paid, work these long hours, or enjoy it as much as I do. The fact that somebody already pays me to write code for them means I'm not really interested in writing your code for you, and neither are most other folks here. I am interested in helping you learn to write your own code and build your own software, but handing out solutions on a plate is not how that gets done, even if I had the time and the patience to write your PHP for you.

    First thing you need to get used to is finding answers for yourself. As you've hopefully gathered from the responses here, folks tend to react badly when people come along looking for solutions on a plate, or some step-by-step answer to a problem that simply doesn't have one single solution that can be written out in a few minutes.

    Google is your friend. For instance, if you'd googled "PHP MySQL", this would have been one of the first hits, which should get you started;
    http://www.freewebmasterhelp.com/tutorials/phpmysql


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    A register would be an insert statement.


  • Registered Users, Registered Users 2 Posts: 1,181 ✭✭✭ronkmonster


    Your code looks alright for logging in with one exception. Don't store passwords in plaintext in your database. Do a search on storing a hash on the file, eg. MD5. This will give a finger print of the password which you compare when logging in.

    You need to google for sql insert. First link will explain the basics, you need to make it work with the code you have.


  • Closed Accounts Posts: 112 ✭✭gahim


    So can someone give me a useful link instead of giving out to me?

    The web builder is already done, now it's the SQL, this is the last day until I have to publish and complete it, only needed is the registration and login form, login form I think is done now its just the registration...


  • Closed Accounts Posts: 112 ✭✭gahim


    Hi Everyone,
    For the database to store information such as

    the title, email, username and password

    should I add it to this table, and how do I?

    Thanks

    I have attached the image


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    You'll need to use an SQL Insert statement: http://www.w3schools.com/sql/default.asp

    Then you'll need to execute the statement from you're form through php, find out how to execute sql statememts from php.


  • Closed Accounts Posts: 112 ✭✭gahim


    http://www.w3schools.com/sql/sql_insert.asp

    The error I am getting when I put in
    INSERT INTO users
    VALUES (title, email)

    #1136 - Column count doesn't match value count at row 1

    I have no idea what that means, I was doing some research and it just confused me more, thanks...

    :confused::confused::confused::D:D:D


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    First of all, your users table from before contains id, login, password. Why are you trying to insert Title and email into this table?

    Secondly, if you dont' specify the fields you want to enter, it will assume you want to enter the 3 fields (3) but you only specifying 2 values.

    You need to start with basics and read material on the internet and practice. You can't just throw random code out and hope it works and ask why it doesn't then.


  • Closed Accounts Posts: 112 ✭✭gahim


    gahim wrote: »
    So can someone give me a useful link?

    The web builder is already done, now it's the SQL, this is the last day until I have to publish and complete it, only needed is the registration and login form, login form I think is done now its just the registration...

    Could someone give me the code for SQL insert?


  • Subscribers Posts: 9,716 ✭✭✭CuLT


    gahim wrote: »
    Could someone give me the code for SQL insert?
    http://dev.mysql.com/doc/refman/5.1/en/insert.html


  • Advertisement
  • Closed Accounts Posts: 112 ✭✭gahim


    I need to add the fields email & title...

    I need this done asap, what code should I use to enter into the SQL, I want the database to store

    • Username
    • Password
    • Email
    • Title
    The title is the title of the website...

    What code should I put in, I was on http://www.w3schools.com/sql/sql_insert.asp but the codes just gave me errors.


  • Closed Accounts Posts: 112 ✭✭gahim


    gahim wrote: »
    I need to add the fields email & title...

    I need this done asap, what code should I use to enter into the SQL, I want the database to store

    • Username
    • Password
    • Email
    • Title
    The title is the title of the website...

    What code should I put in, I was on http://www.w3schools.com/sql/sql_insert.asp but the codes just gave me errors.

    Just for confirmation

    INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
    [INTO] users ]
    {email | title} ({expr | DEFAULT},...),(...),...
    [ ON DUPLICATE KEY UPDATE
    col_name=expr
    [, col_name=expr] ... ]

    Is this correct, I just don't want to mess up my database :)

    Thanks


  • Registered Users, Registered Users 2 Posts: 8,070 ✭✭✭Placebo




  • Registered Users, Registered Users 2 Posts: 23,212 ✭✭✭✭Tom Dunne


    gahim wrote: »
    I need to add the fields email & title...

    http://dev.mysql.com/doc/refman/5.1/en/alter-table.html
    gahim wrote: »
    I need this done asap

    Not helping your cause.
    gahim wrote: »
    • Username
    • Password
    • Email
    • Title
    The title is the title of the website...

    What code should I put in, I was on http://www.w3schools.com/sql/sql_insert.asp but the codes just gave me errors.

    You need to understand what you are trying to do. You need to understand database structure and how you can use that to store your data.

    Just randomly throwing scripts against a database is going to cause you grief both in the short term and the long term.


  • Registered Users, Registered Users 2 Posts: 1,181 ✭✭✭ronkmonster


    The problem you have is that your database has 3 fields in it and you are only supplying 2 fields. There is a way to show which columns you want your 2 fields to match up to, ignoring the other field (if it is allowed to be null).

    http://www.1keydata.com/sql/sqlinsert.html
    first example here should be enough to continue.


  • Closed Accounts Posts: 112 ✭✭gahim


    I clicked on the SQL tab and entered this into the field
    INSERT INTO users
    VALUES ('title', 'email')

    and the result

    SQL query:
    INSERT INTO users
    VALUES ( 'title', 'email'
    )
    MySQL said:
    #1136 - Column count doesn't match value count at row 1

    :confused::confused::confused::confused::confused::confused:


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    gahim wrote: »
    I clicked on the SQL tab and entered this into the field
    INSERT INTO users
    VALUES ('title', 'email')

    and the result

    SQL query:
    INSERT INTO users
    VALUES ( 'title', 'email'
    )
    MySQL said:
    #1136 - Column count doesn't match value count at row 1

    :confused::confused::confused::confused::confused::confused:
    I and another person have told you the problem with this. I can't spell it out anymore I'm afraid.


  • Closed Accounts Posts: 112 ✭✭gahim


    "The problem you have is that your database has 3 fields in it and you are only supplying 2 fields. There is a way to show which columns you want your 2 fields to match up to, ignoring the other field (if it is allowed to be null)."

    What do you mean by this? I want it to have 4 fields, and to login 2 fields is required...


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Then alter the table and add in those extra fields. Then when you've all your fields sorted, then do the insert with the appropriate values.


  • Advertisement
  • Closed Accounts Posts: 112 ✭✭gahim


    Is there somewhere with step by step instructions on how to add fields etc..?


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    There is if you searched google:

    http://www.google.ie/search?hl=en&source=hp&q=adding+column+to+table+mysql&btnG=Google+Search&meta=&aq=f&oq=

    2nd result.

    Why are you so obsessed with step by step. There is no such thing as step by step as pointed out before. You need to read and learn and apply it to your own problem. Not every problem is identical.


  • Registered Users, Registered Users 2 Posts: 23,212 ✭✭✭✭Tom Dunne


    gahim wrote: »
    Is there somewhere with step by step instructions on how to add fields etc..?

    As I posted about 30 minutes ago:
    Tom Dunne wrote: »

    Seriously, you need to read what we are telling you.


  • Closed Accounts Posts: 112 ✭✭gahim


    Hi,

    Thanks for your help, I am new to my SQL, could you tell me, I have to add two columes and then add the field in each colume?

    Thanks Again


  • Closed Accounts Posts: 112 ✭✭gahim


    ALTER TABLE users ADD email VARCHAR(60);

    ALTER TABLE users ADD title VARCHAR(60);

    Is that what I should put?

    Thanks


  • Registered Users, Registered Users 2 Posts: 8,584 ✭✭✭TouchingVirus


    gahim wrote: »
    So can someone give me a useful link instead of giving out to me?

    We're not here to give you links, that is google's job. We are here to help when you show us code, and say it's not working despite you researching X, Y and Z methods to fix it.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    gahim wrote:
    ALTER TABLE users ADD email VARCHAR(60);

    ALTER TABLE users ADD title VARCHAR(60);

    Is that what I should put?

    Thanks
    Probably. Give it ago and see if it's what you want. You can delete them after.

    I've a feeling you are simply not reading tutorials but jumping to code and inserting it hoping that it work. You need to read a bit more.


  • Registered Users, Registered Users 2 Posts: 8,584 ✭✭✭TouchingVirus


    gahim wrote: »
    ALTER TABLE users ADD email VARCHAR(60);

    ALTER TABLE users ADD title VARCHAR(60);

    Is that what I should put?

    Thanks

    Back up your SQL database, run it and see where it leads :) Try the code first


  • Registered Users, Registered Users 2 Posts: 1,181 ✭✭✭ronkmonster


    gahim wrote: »
    "The problem you have is that your database has 3 fields in it and you are only supplying 2 fields. There is a way to show which columns you want your 2 fields to match up to, ignoring the other field (if it is allowed to be null)."

    What do you mean by this? I want it to have 4 fields, and to login 2 fields is required...
    add in the 4th field so. and you can have 20 fields but still only use the 2 for login. thats irrelevant.

    when you register, you insert a new row of data to your database, usually the full 4 items.
    when you login, you only to need to read (select) the fields of the row you need, username and password.


  • Closed Accounts Posts: 112 ✭✭gahim


    Yesss it works!

    Now its registration


  • Closed Accounts Posts: 112 ✭✭gahim


    Hi,
    I have created a form beta.gahim.com/start/index.php form is set POST to register.php, I have created register.php but don't know what to put inside...


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 515 ✭✭✭NeverSayDie


    gahim wrote: »
    Hi,
    I have created a form beta.gahim.com/start/index.php form is set POST to register.php, I have created register.php but don't know what to put inside...

    That question has already been answered several times over in this thread.
    Evil Phil wrote: »
    You'll need to use an SQL Insert statement: http://www.w3schools.com/sql/default.asp

    Then you'll need to execute the statement from you're form through php, find out how to execute sql statememts from php.
    CuLT wrote: »
    add in the 4th field so. and you can have 20 fields but still only use the 2 for login. thats irrelevant.

    when you register, you insert a new row of data to your database, usually the full 4 items.
    when you login, you only to need to read (select) the fields of the row you need, username and password.
    Google is your friend. For instance, if you'd googled "PHP MySQL", this would have been one of the first hits, which should get you started;
    http://www.freewebmasterhelp.com/tutorials/phpmysql


  • Registered Users, Registered Users 2 Posts: 1,181 ✭✭✭ronkmonster


    Ok, if your form is set to send data to register.php

    setup your register.php to assign those 4 values to variables and output them to page.

    post that code here and i'll help you with next stage.


  • Registered Users, Registered Users 2 Posts: 8,584 ✭✭✭TouchingVirus


    Ok, if your form is set to send data to register.php

    setup your register.php to assign those 4 values to variables and output them to page.

    post that code here and i'll help you with next stage.

    This is for a BT Young Scientist project, I do hope you won't be holding the OP's hand because you're not getting the award if they win :D


  • Closed Accounts Posts: 112 ✭✭gahim


    Hi Guys,
    Sorry, I did everything on http://www.trap17.com/index.php/simple-php-login-registration-system_t52533.html

    to be more specific

    I have login2.php which contains
    <?php
    include 'mysql-connect.php';

    $username = $_POST;
    $password = $_POST;
    $query1 = mysql_query("SELECT * FROM users WHERE username='$username'");
    $result = mysql_num_rows($query1);
    if($result == 0)
    {
    include '<h1>Sorry!</h1>The username you specified does not exist!';
    }
    else
    {

    $checkuser = mysql_query("SELECT * FROM users WHERE username='$username'");

    $row = mysql_fetch_array($checkuser);
    $password2 = $row;
    $status = $row;
    if ($password == $password2)
    {
    Location: http://beta.gahim.com/Builder
    }
    else
    {
    echo '<h1>Error!</h1>The username and password combination you entered does not match the ones we have in our database.';
    }

    }
    ?>



    register.php

    <?php
    include 'mysql-connect.php';
    $username = $_POST;
    $password = $_POST;
    $name = $_POST;
    $email = $_POST;
    $title = $_POST;

    $result = mysql_num_rows(mysql_query("SELECT * FROM TABLENAME WHERE username='$username'"));
    if($result == 1)
    {
    echo ‘<h1>ERROR!</h1>Ah Sorry, that username is not available!’;
    }
    else
    {
    mysql_query("INSERT INTO TABLENAME (username, password, name, email, title)
    VALUES ('$username', '$password', '$name', '$email', 'title')");

    echo '
    <p>Cool, you now have a website!</p>
    <p><a href="login.php">Click here</a> to login and start building!</p>‘;
    ?>

    mysql-connect.php

    <?php
    $con = mysql_connect("localhost","gahimcom_gahim","---mypasswordhere---");
    mysql_select_db("gahimcom_members", $con);
    ?>

    beta.gahim.com/start

    If you go to the page you will see the form code


    I am doing something wrong as it doesn't work...

    I think it's the location:beta.gahim.com/builder

    (the success page)


  • Closed Accounts Posts: 112 ✭✭gahim


    gahim wrote: »
    Hi Guys,
    Sorry, I did everything on http://www.trap17.com/index.php/simple-php-login-registration-system_t52533.html

    to be more specific

    I have login2.php which contains
    <?php
    include 'mysql-connect.php';

    $username = $_POST;
    $password = $_POST;
    $query1 = mysql_query("SELECT * FROM users WHERE username='$username'");
    $result = mysql_num_rows($query1);
    if($result == 0)
    {
    include '<h1>Sorry!</h1>The username you specified does not exist!';
    }
    else
    {

    $checkuser = mysql_query("SELECT * FROM users WHERE username='$username'");

    $row = mysql_fetch_array($checkuser);
    $password2 = $row;
    $status = $row;
    if ($password == $password2)
    {
    Location: http://beta.gahim.com/Builder
    }
    else
    {
    echo '<h1>Error!</h1>The username and password combination you entered does not match the ones we have in our database.';
    }

    }
    ?>



    register.php

    <?php
    include 'mysql-connect.php';
    $username = $_POST;
    $password = $_POST;
    $name = $_POST;
    $email = $_POST;
    $title = $_POST;

    $result = mysql_num_rows(mysql_query("SELECT * FROM TABLENAME WHERE username='$username'"));
    if($result == 1)
    {
    echo ‘<h1>ERROR!</h1>Ah Sorry, that username is not available!’;
    }
    else
    {
    mysql_query("INSERT INTO TABLENAME (username, password, name, email, title)
    VALUES ('$username', '$password', '$name', '$email', 'title')");

    echo '
    <p>Cool, you now have a website!</p>
    <p><a href="login.php">Click here</a> to login and start building!</p>‘;
    ?>

    mysql-connect.php

    <?php
    $con = mysql_connect("localhost","gahimcom_gahim","---mypasswordhere---");
    mysql_select_db("gahimcom_members", $con);
    ?>

    beta.gahim.com/start

    If you go to the page you will see the form code


    I am doing something wrong as it doesn't work...

    I think it's the location:beta.gahim.com/builder

    (the success page)

    I don't know what you mean, I have set the variables and output page, could someone confirm the sulfess page code is right as I wrote that myself. :)


  • Registered Users, Registered Users 2 Posts: 1,181 ✭✭✭ronkmonster


    This is for a BT Young Scientist project, I do hope you won't be holding the OP's hand because you're not getting the award if they win :D

    just helping to show how to develop an idea. build up from smaller parts.

    first stage make sure you getting the right data across.

    OP from your code, put an echo 'test'; in your code start near top and work down until it doesn't appear anymore. your problem is between the working echo and the non-working one.


  • Registered Users, Registered Users 2 Posts: 1,181 ✭✭✭ronkmonster


    gahim wrote: »
    I don't know what you mean, I have set the variables and output page, could someone confirm the sulfess page code is right as I wrote that myself. :)

    Its not the builder page. it doesn't move from the login2.php page

    do the echo thing from my last post. php doesn't display stuff if even small thing is wrong

    put echo 'test'; after
    include 'mysql-connect.php';


  • Closed Accounts Posts: 112 ✭✭gahim


    Put <?php
    echo "test";?> on the top of which page? login2.php


  • Registered Users, Registered Users 2 Posts: 1,181 ✭✭✭ronkmonster


    yes

    when you try login, look at the address bar and you can see that address is still login2.php

    that means it didn't get transferred to next page. so problem is probably before that part


  • Closed Accounts Posts: 112 ✭✭gahim


    I have gone to page after page and read everything, done everything and it doesn't work!

    I have explained whats on my page, what do you mean by putting this echo test on the page, how will that help?

    Again I would like to thank everyone for there help, I am new to databases, in fact 3 days ago I didn't even know what a database was...


  • Advertisement
Advertisement