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

MySQL Database Login/Registration

Options
135

Comments

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


    But like we said before, registration is only an insert into the users table!


  • Registered Users Posts: 35,524 ✭✭✭✭Gordon


    gahim wrote: »
    3 days ago I didn't even know what a database was...
    gahim, are you sharing this account with someone? You are giving out mixed signals. Here you are saying that you don't know what a database is, and in the thread on the design forum I said this:
    Gordon wrote: »
    Also, am I right in thinking that this is a website to showcase your young scientist and technology skills? I don't mean to sound rude, and sorry if it comes across rudely, but you might want to think about getting a coder onboard that will be able to upskill you on the technology aspect if you want this project to work. Building a free website builder site can't be an easy thing, you need a coder to make this work in my opinion.

    and you replied with this, implying you know how to write php code.
    gahim wrote: »
    I have finnished the builder, I am good at code and I have done everything right in this code

    So, are you letting someone else post with your gahim account also? Someone that knows more php than you do?


  • Registered Users Posts: 515 ✭✭✭NeverSayDie


    gahim wrote: »
    Hi Everyone,
    I deleted everything I had done and started from scratch, using http://www.trap17.com/index.php/phpmysql-loginregister_t9487.html I did it but (as you may have guessed) it doesn't work, :(

    Can anyone recommend a link that can help me with login/registration linking to mysqldatabase, I did a search on Google and used 3.

    The only one that worked was http://www.howtodothings.com/computers-internet/how-to-make-a-login-system-for-your-website#comment-8341 BUT it had no registration form instructions.
    Webmonkey wrote: »
    But like we said before, registration is only an insert into the users table!

    What he said. Forget about registration. Learn how to insert stuff into a MySQL database from a PHP script.

    Important part of being able to write code is describing a problem in its component parts, expressed as technical steps. In this case, "registration" involves adding a user's data to the database, and very little else. So find out how to do that, using one of the several links and suggestions we've all provided for you.


  • Closed Accounts Posts: 112 ✭✭gahim


    Reply to Administrater
    Two of us, I am new to DATABASES not coding and websites, I am doing this as a challenge and we have finnished the builder...

    Can I add that the whole project is about the website builder not this login and register stuff...

    Back to my question

    I know the registration form is a simple insert into the table


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


    Important part of being able to write code is describing a problem in its component parts, expressed as technical steps. In this case, "registration" involves adding a user's data to the database, and very little else. So find out how to do that, using one of the several links and suggestions we've all provided for you.

    OP, this is an very important point. Write out the steps logically you think are involved in registering a user on your site.

    We'll take a look and point out anything you are missing. Then you can look up how to do each stage when you know exactly what you are trying to do.

    We could just tell you how to do it but you will learn more this way.


  • Advertisement
  • Closed Accounts Posts: 112 ✭✭gahim


    All the fields have been added to the database name gahimcom_members (table is gahimcom_users)...

    I am still working on it....

    I will come back to you with my result as I need some expert advice :)


  • Closed Accounts Posts: 112 ✭✭gahim


    What I have done

    http://beta.gahim.com/start/login.php
    <title>Login</title>
    <FONT FACE="Arial">
    <?
    session_name("Login");
    session_start();
    session_destroy();

    if($_GET == "failed") {
    print $_GET;
    }
    ?>
    <form name="login_form" method="post" action="log.php?action=login">
    Login: <input type="text" name="username"><BR>
    Password: <input type="password" name="password"><BR>
    <input type="submit" value="Start Building">
    </form>
    </font>

    http://beta.gahim.com/start/log.php
    <?
    session_name("Login");
    session_start();

    if($_GET == "login") {
    $conn = mysql_connect("localhost","gahimcom","aransean11"); // your MySQL connection data
    $db = mysql_select_db("gahimcom_members"); //put your database name in here
    $name = $_POST;
    $q_user = mysql_query("SELECT * FROM gahimcom_users WHERE login='$name'");

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

    $query = mysql_query("SELECT * FROM gahimcom_users WHERE login='$name'");
    $data = mysql_fetch_array($query);
    if($_POST == $data) {
    session_register("name");
    header("Location: http://beta.gahim.com/start"); // 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");
    }
    ?>

    http://beta.gahim.com/start/process.php
    <?
    $name=$_POST;
    $email=$_POST;
    $email=$_POST;
    $email=$_POST;
    $email=$_POST;

    $location=$_POST;
    mysql_connect("localhost", "gahimcom", "aransean11") or die(mysql_error());
    mysql_select_db("gahimcom_members") or die(mysql_error());
    mysql_query("INSERT INTO `data` VALUES ('$name', '$email', '$password', '$username', '$title')");
    Print "You are now signed up, you may now login!";
    ?>

    http://beta.gahim.com/start
    Code for the registration form

    If you signup then try login at http://beta.gahim.com/start/login.php it doesn't work...


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


    gahim, if there's two of you I suggest you get an account each. Actually, Gordon is probably going to insist on it. Also it will make life easier for you both.

    1 of you should focus on learning the php side and the other should focus on learning the mysql side of things.


  • Closed Accounts Posts: 112 ✭✭gahim


    Gahim is my account and my project partner doesn't have a boards.ie account, someone from spiralhosting recommended boards.ie. My partner is finalizing a few things with the website builder which isn't oioon the net and I am doing the SQL.

    I gave you all the codes and I was wondering if you were able to see whats wrong with it...

    Thanks


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


    In your code, I hope you aren't posting your real username and password to your account -in the mysql connection :)

    Before this line
    if($_POST == $data) {

    put this as a test
    echo $_POST;
    echo $data;

    just confirm that you are sending the right value across and that you are pulling something out of the database

    Update: Can you check your database for a username 'ronkmonster'
    I added one but can't login. says invalid user

    Before this line in log.php
    $q_user = mysql_query("SELECT * FROM gahimcom_users WHERE login='$name'");
    add echo '$name';
    check that name is being assigned value


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


    Ok, can you explain this line
    process.php
    mysql_query("INSERT INTO `data` VALUES ('$name', '$email', '$password', '$username', '$title')");

    compared to
    log.php
    $query = mysql_query("SELECT * FROM gahimcom_users WHERE login='$name'");

    looks like its inserting into a different table than you reading from


  • Closed Accounts Posts: 112 ✭✭gahim


    Hi,
    Thanks

    I have put that in and I have seen no difference, still invalid user...

    The code is still active on the page...

    :confused::confused::confused:


  • Closed Accounts Posts: 112 ✭✭gahim


    log.php is for the login form

    process.php is for the signup form

    As you can see the first thing we do is assign variables to the data from the previous page. We then just query the database to add this new information.
    Of course before we try it we need to make sure the table actually exists. Executing this code should create a table that can be used with our sample files:
    CREATE TABLE data (name VARCHAR(30), email VARCHAR(30), location VARCHAR(30));


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


    Yes, but if you insert into table A you have to read from table A
    it looks like you insert into table data and read from gahimcom_users


  • Closed Accounts Posts: 112 ✭✭gahim


    Hi,
    I want to insert into table called gahimcom_users in the gahimcom_members database

    May I ask what you mean by read from?


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


    gahim wrote: »
    Hi,
    I want to insert into table called gahimcom_users in the gahimcom_members database

    May I ask what you mean by read from?

    $query = mysql_query("SELECT * FROM gahimcom_users WHERE login='$name'");
    this is you reading from gahimcom_users

    this is what you need for insert
    mysql_query("INSERT INTO gahimcom_users VALUES ('$name', '$email', '$password', '$username', '$title')");

    you were inserting into the wrong database, so new users registered wasn't in the gahimcom_users table to be read for logins


  • Closed Accounts Posts: 112 ✭✭gahim


    Hi,
    I have put that into the process.php file

    now the code is
    <?
    $name=$_POST;
    $email=$_POST;
    $email=$_POST;
    $email=$_POST;
    $email=$_POST;

    $location=$_POST;
    mysql_connect("localhost", "gahimcom", "aransean11") or die(mysql_error());
    mysql_select_db("gahimcom_members") or die(mysql_error());
    mysql_query("INSERT INTO *gahimcom_users* VALUES ('$name', '$email', '$password', '$username', '$title')");
    Print "You are now signed up, you may now login!";
    ?>

    When I try to login (http://beta.gahim.com/start/login.php) it says invalid user, do you think there is something wrong with the login then?


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


    get rid of those * around the table name


  • Closed Accounts Posts: 112 ✭✭gahim


    I have done this, still when I login it doesn't work

    Is there anything maybe in the signup form http://beta.gahim.com/start/index.php that doesn't work?
    :confused::D


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


    does it work with any users details?
    if you enter details directly into the database and then try login with those details, does it work?


  • Advertisement
  • Closed Accounts Posts: 112 ✭✭gahim


    does it work with any users details?
    if you enter details directly into the database and then try login with those details, does it work?

    How do I put in user details, I have to put in a code into the MySQLAdmin...

    I click on SQL and what code do I enter?


  • Registered Users Posts: 981 ✭✭✭fasty


    Why not check if the data went into the database when you do a sign up? I know you say you can code but this is simple stuff. If you add some data, checking the data got added seems prudent whether it's a database, a file or whatever.

    Also, you posted the login to your SQL database by accident. I wonder if that's the same login for other aspects of your site... Not that it matters since you have left yourself open to SQL injection attacks.


  • Closed Accounts Posts: 112 ✭✭gahim


    Hi,
    I know that I gave out a fake password, I don't understand what I did wrong with the login?

    The fields are
    username, password, name, email, title

    I hope to get this done by today (since it's 12)

    Could you explain on which page I need to change the code?

    Thanks :confused::D


  • Registered Users Posts: 18,272 ✭✭✭✭Atomic Pineapple


    did any data get passed into the database?

    or do you have any data to allow a test login already in the database?


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


    gahim wrote: »
    How do I put in user details, I have to put in a code into the MySQLAdmin...

    I click on SQL and what code do I enter?

    Does your web host not provide phpMyAdmin to manage your database?

    something like this in sql

    INSERT INTO gahimcom_users VALUES ('ronkmonster', 'ronkmonster@ronk.ie', 'ronk, 'ronkmonster', 'myTitle');

    usually if you are doing the login first, you would have some test data manually inserted into the database. how else would you know that the login code you write is correct???

    if you are using the commandline tool for mysql you can check if anything got added into your database with

    select * from gahimcom_users;


    EDIT

    your code is doing this (simplified)
    if(mysql_num_rows($q_user) == 1) {
    code if something in database
    }
    else
    {
    wrong user
    }

    it always saying wrong user means the users we try use are not in the database.
    you need to manually add at least one user to the database as a test before even trying to fix your login


  • Closed Accounts Posts: 112 ✭✭gahim


    Does your web host not provide phpMyAdmin to manage your database?

    something like this in sql

    INSERT INTO gahimcom_users VALUES ('ronkmonster', 'ronkmonster@ronk.ie', 'ronk, 'ronkmonster', 'myTitle');

    usually if you are doing the login first, you would have some test data manually inserted into the database. how else would you know that the login code you write is correct???

    if you are using the commandline tool for mysql you can check if anything got added into your database with

    select * from gahimcom_users;


    EDIT

    your code is doing this (simplified)
    if(mysql_num_rows($q_user) == 1) {
    code if something in database
    }
    else
    {
    wrong user
    }

    it always saying wrong user means the users we try use are not in the database.
    you need to manually add at least one user to the database as a test before even trying to fix your login

    With your first code to put into the SQL I recieved this

    Error

    There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem
    ERROR: Unclosed quote @ 103
    STR: '
    SQL: INSERT INTO gahimcom_users VALUES ('ronkmonster', 'ronkmonster@ronk.ie', 'ronk, 'ronkmonster', 'myTitle');

    SQL query:
    INSERT INTO gahimcom_users VALUES ('ronkmonster', 'ronkmonster@ronk.ie', 'ronk, 'ronkmonster', 'myTitle');
    MySQL said:
    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ronkmonster', 'myTitle')' at line 1



    and then your secound code returned says
    MySQL returned an empty result set (i.e. zero rows). (Query took 0.0006 sec)

    Basically the table is emply :( and something is not letting me insert


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


    Right can you please tell us what fields and their types are in that table. We're going no where with this.


  • Closed Accounts Posts: 263 ✭✭HandWS LTD


    [URL]http://beta.gahim.com/start/log.php[/URL]
     <?
    session_name("Login");
    session_start();
    
    if($_GET['action'] == "login") {
    $conn = mysql_connect("localhost","gahimcom","aransean11"); // your MySQL connection data
    $db = mysql_select_db("gahimcom_members"); //put your database name in here
    $name = $_POST['username'];
    $q_user = mysql_query("SELECT * FROM gahimcom_users WHERE login='$name'");
    
    if(mysql_num_rows($q_user) == 1) {
    
    $query = mysql_query("SELECT * FROM gahimcom_users WHERE login='$name'");
    $data = mysql_fetch_array($query);
    if($_POST['password'] == $data['password']) {
    session_register("name");
    header("Location: http://beta.gahim.com/start"); // success page. put the URL you want
    exit;
    

    Ok this thread is confusing. Two people on the same account. The first and only thing you should never do is post your real database name, username and password. I sure hope you didn't because anybody can access it if you did. So if you did....i'd recommend you change it immediately.
    header("Location: http://beta.gahim.com/start"); // success page. put the URL you want
    

    Why is your success page shown at that location above? Thats a registration page. It needs to be a different page that is displayed after your users login. e.g in your case register.php as its blank as seen in the other thread you or your colleague opened:
    http://www.boards.ie/vbulletin/showthread.php?t=2055782187&page=5

    Have you added:
    [COLOR=#0000bb]	<?
     	[/COLOR][COLOR=#007700]require([/COLOR][COLOR=#dd0000]"log.php"[/COLOR][COLOR=#007700]);
     	[/COLOR][COLOR=#0000bb]?>[/COLOR]
     [COLOR=#0000bb]	Printing the user name in the screen is very easy. Just add this code:[/COLOR]
     [COLOR=#0000bb]	<? [COLOR=#007700]print [/COLOR][COLOR=#0000bb]$_SESSION[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]"name"[/COLOR][COLOR=#007700]]; [/COLOR][COLOR=#0000bb]?>[/COLOR][/COLOR] 
    
    to the top of your register.php file? or as you are originally sending your users to after they register .... to http://beta.gahim.com/start


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


    Gahim for god sake change your password. I'm inside your control panel!


  • Advertisement
  • Closed Accounts Posts: 112 ✭✭gahim


    Webmonkey wrote: »
    Right can you please tell us what fields and their types are in that table. We're going no where with this.

    Please see the image attached


Advertisement