Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 3 123 LastLast
Results 1 to 10 of 23
  1. #1
    Join Date
    Dec 2007
    Location
    Toronto, Ontario, Canada
    Posts
    689
    Tokens
    0

    Default Not adding to DB [PHP]

    When you press register, it doesn't add the contents to the database. All it does is refresh the page.

    PHP Code:
    <?php

    if($logged['in'] == 1){
        
    header("Location: index.php");
    }

    if(
    row_exists('users','ip',$ip)){ ?>
        Your IP ($ip) has already been registered with.
    <?php }

    else{
        if(
    $_POST['register']){
            
    $username clean($_POST['username']);
            
    $email clean($_POST['email']);
            
    $password clean($_POST['password']);
            
    $cpassword clean($_POST['cpassword']);
            
            
    $errors 0;
            
    $error_message '';
            
            if(empty(
    $username) || empty($email) || empty($password) || empty($cpassword)){
                
    $errors++;
                
    $error_message 'All fields must be filled in.';
            }
            
            if(
    row_exists('users','username',$username)){
                
    $errors++;
                
    $error_message 'That username is already taken.';
            }
            
             if(
    row_exists('users','email',$email) || !is_valid_email($email)){
                 
    $errors++;
                
    $error_message 'That email is alreayd in use or is incorrect.';    
             }
             
             
    $password enc($password);
             
    $cpassword enc($cpassword);
             
             if(
    $password != $cpassword){
                 
    $errors++;
                 
    $error_message 'The two passwords you entered do not match.';
             }
             
             if(
    $errors 0){
                 
    $insert mysql_query("INSERT INTO `users` (`username`,`password`,`email`,`ip`,`joindate`,`jointime`) VALUES ('".$username."','".$password."','".$email."','".$ip."','".$date."','".$time."')");
                 
                 
    $subject "Welcome to willSystem";
                 
    $body "Thanks for joining (test message from willSystem demo.)";
                 
    send_mail($email,$subject,$body);
                 
                 
    ?>

    Thanks for joining, you may now <a href="login.php">login</a>.
                 
    <?php

    exit();
             } else{
                 echo 
    $error_message;
             }
             
        }

    ?>
    <form method="post">
    Username<br />
    <input type="text" name="username" value="<?=$username?>" maxlength="12"><br /><br />
                     
    Email<br />
    <input type="text" name="email" value="<?=$email?>"><br /><br />
                     
    Password<br />
    <input type="password" name="password"> Confirm <input type="password" name="cpassword"><br /><br />
                     
    <input type="submit" name="register" value="Register"><br /><br />
                     
    All fields are required.
    </form>

    <?php
    }
    ?>
    +rep

    Moved by Invent (Forum Moderator) from Designing & Development: Please post in the correct forum next time, thanks .
    Last edited by Invent; 28-07-2008 at 04:41 PM.

  2. #2
    Join Date
    May 2008
    Posts
    605
    Tokens
    0

    Default

    Nevermind, got an error.

  3. #3
    Join Date
    Dec 2007
    Location
    Toronto, Ontario, Canada
    Posts
    689
    Tokens
    0

    Default

    Here:

    PHP Code:
    <?php

    ob_start
    ();
      

    ob_start("ob_gzhandler");
      

    session_start();

    $database = array();
     
    $database['host'] = 'localhost';
    $database['name'] = 'x'
    $database['user'] = 'x'
    $database['pass'] = 'x'

    $mysql_connection mysql_pconnect($database['host'], $database['user'], $database['pass']);

    mysql_select_db($database['name'], $mysql_connection);

    $sess_id = (!$_SESSION['id']) ? $_SESSION['id'];
    $sess_username = (!$_SESSION['username']) ? 'nonexistantuser_DIE' $_SESSION['username'];
    $sess_password = (!$_SESSION['password']) ? 'nonexistantpass_DIE' $_SESSION['password'];

    $query mysql_query("SELECT * FROM `users` WHERE `id`='".$sess_id."' AND `username`='".$sess_username."' AND `password`='".$sess_password."' LIMIT 1");
    $count mysql_num_rows($query);

    $logged = array();

    if(
    $count == 0){
    $logged['username'] = 'Guest';
    $logged['level'] = 3;
    $logged['in'] = 0;
    }else{
    $logged mysql_fetch_array($query);
    $logged['in'] = 1;
    }
      
    $date date("m.d.Y"); /* Date - Month.Day.Year */
    $time time(); /* Numerical Time */
    $timestamp date("g:i A"); /* Time - Hour:Minute AM/PM */
    $ip getenv('REMOTE_ADDR'); /* Ip Address */
     
    ?>

  4. #4
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    Don't use ! in your ternarys, instead just reverse the statements.

    You shouldn't be directly editing data taken from a database ie $logged['in']

    You mispelt mysql_connect

    is $_SESSION['id'] boolean?

    You have a lot of pointless ternarys

    I think your mistaking booleans and wether a string is null/not set

    instead get an ip like $_SERVER['REMOTE_ADDR']

    single quotes are faster than doubles

    your mistaking your variable names (time types) (just a personal preference)

    $logged['in'] should be set as true or false, not 1 or 0.

    I personally wouldn't use a mysql connection resource in your database selector

    I don't know where your going with the output buffering

    a few personal preferences but some are needed.

    please check your code in a debugger or an ide, coming on here asking about mysql_pconnect, it's to be honest wasting everybodys time when you could see that individual mistake in quarter of a second on an ide or a debugger.


    ok your first page

    ips are dynamic a lot of the time so don't use them


    your database schema looks bad - ip - as a row?

    ++$error;
    is faster than
    $error++

    Use echo equals like <?= $var ?>

    where are some of your functions coming from?

    such as is_valid_email




    HOW THE HECK ARE YOU DOING ALL THIS WITHOUT A SINGLE ERROR TO PRODUCE FOR US?



    Wow...

    as for your html you didn't do much with <form> atleast add action


    oh and get rid of $insert = ...why is that there in the first place!!??!
    Last edited by Hypertext; 22-07-2008 at 02:56 AM.
    How could this hapen to meeeeeeeeeeeeeee?lol.

  5. #5
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    I suggest that everyone read this Quite funny. heh.

    Quote Originally Posted by Hypertext View Post
    Don't use ! in your ternarys, instead just reverse the statements.

    You shouldn't be directly editing data taken from a database ie $logged['in']

    You mispelt mysql_connect

    is $_SESSION['id'] boolean?

    You have a lot of pointless ternarys

    I think your mistaking booleans and wether a string is null/not set

    instead get an ip like $_SERVER['REMOTE_ADDR']

    single quotes are faster than doubles

    your mistaking your variable names (time types) (just a personal preference)

    $logged['in'] should be set as true or false, not 1 or 0.

    I personally wouldn't use a mysql connection resource in your database selector

    I don't know where your going with the output buffering

    a few personal preferences but some are needed.

    please check your code in a debugger or an ide, coming on here asking about mysql_pconnect, it's to be honest wasting everybodys time when you could see that individual mistake in quarter of a second on an ide or a debugger.


    ok your first page

    ips are dynamic a lot of the time so don't use them


    your database schema looks bad - ip - as a row?

    ++$error;
    is faster than
    $error++

    Use echo equals like <?= $var ?>

    where are some of your functions coming from?

    such as is_valid_email




    HOW THE HECK ARE YOU DOING ALL THIS WITHOUT A SINGLE ERROR TO PRODUCE FOR US?



    Wow...

    as for your html you didn't do much with <form> atleast add action


    oh and get rid of $insert = ...why is that there in the first place!!??!
    Okay, don't be stupid.. you don't know anything about coding.

    After reading your post.. and seeing your stupid remarks about what you think, I have to laugh.. :eusa_clap good job.. it was all a joke right?

    Sadly not with you.. you are actually being serious.. you think what you just said was correct.

    No.. no it wasn't.

    Lets start off with some of the things you just said, and address why they are the most idiotic remarks about PHP I think I have heard yet.

    About as bad as someone asking what echo does.



    Why do that, and increase the file size and coding.. that is not the preferred method.. use !=, but not !$statement.

    You shouldn't be directly editing data taken from a database ie $logged['in']
    Why not? It Isn't editing it on the database.. just the array it is stored on. It is his data.. it is checking the array, not the database..

    Not the safest method, but it works for what he is doing.. duh.

    is $_SESSION['id'] boolean?
    Why would you have an id with letters?

    instead get an ip like $_SERVER['REMOTE_ADDR']
    getenv is the opposite of using a superglobal.. my god read php.net

    single quotes are faster than doubles
    No.. single quotes are for simple strings.. there is no use having a bunch of:

    PHP Code:
    $string 'hey ' $there ' my name is ' $caleb ' I hope ' $you ' ...'
    That is stupid when you can just use a set of "" and be done with it, as PHP parses that string above as each '' being a different string, then joins them.

    So use '' for simple things

    PHP Code:
    $string 'hello'
    "" for variables and other things.. different times for different things..

    don't start going about speeds... you have no clue.

    $logged['in'] should be set as true or false, not 1 or 0.
    Haha.. this is my favorite! My absolute favorite.

    Mr. PHP MAN!

    TRUE/FALSE is 1/0!!!!!!

    I thought you knew all this? All true false is, is a boolean!

    So you are telling him to be setting it to the same thing, are you stupid?

    Don't give advice if you don't know what you are talking about.

    You are trying too hard to be smart.

    I personally wouldn't use a mysql connection resource in your database selector
    Okay dude.. listen.. this isn't a normal mysql connect, it is a pconnect, you normally need a link for it to communicate right as it is persis.

    You want to keep it on the same link! Not start another connection, then you run into problems with MySQL taking up 200MB of RAM.

    Gah.

    I don't know where your going with the output buffering
    Maybe if you read?

    ob_start("ob_gzhandler");
    He is gzipping it! Congratulations for not reading 6th line.

    He is probably using cookies.. you need ob_start(); :rolleyes:

    a few personal preferences but some are needed.

    please check your code in a debugger or an ide, coming on here asking about mysql_pconnect, it's to be honest wasting everybodys time when you could see that individual mistake in quarter of a second on an ide or a debugger.
    You don't need an IDE, it makes it easier yes, but he isn't to the point now where he needs a professional development tool.

    From what I have read, you are on about the same level as him, and neither do you.

    It's to be honest you are wasting everyone's time when you come on here providing wrong advice, wrong coding tips, and stupid points.

    mysql_pconnect is a function to connect to the database.. it isn't ******* mispelled.

    You really need to use PHP.net..

    ips are dynamic a lot of the time so don't use them
    No **** sherlock, you just figured out the internet?

    What other identifying variable do you suggest we use then..? There isn't one, which is why sites log IPs.

    You could use hostname, which just transfers to an IP and vise versa, or include a shockwave movie and grab the MAC id but that is too much of a pain.

    Which is why we use IPs. Gah.

    your database schema looks bad - ip - as a row?
    Yeah, he is storing the IP.. dip****, the ip isn't a row.. it is a column..

    He is either storing the IP when registered, or constantly updating it.. why would you think it is a row?

    ++$error;
    is faster than
    $error++
    It is the SAME thing.. just reversed.. you are telling it to do the same thing.. it is neither faster or slower.. before making a statement.. test it out.. time it.. god.

    Use echo equals like <?= $var ?>
    No.. just no.. that is an awful way to do it.. <? is a shortag, do it the right way if you are going to be telling him how to do it.

    You are going to make him a bad as you.

    [php
    <?php echo $var; ?>
    [/php]

    Simple Put it in your clipboard, or snippets, easy as heck.



    Probably a file he hasn't posted, thought of that?

    HOW THE HECK ARE YOU DOING ALL THIS WITHOUT A SINGLE ERROR TO PRODUCE FOR US?
    All your statements are invalid, so there is no 'doing all this'.

    If you haven't noticed.. it isn't about the PHP.. it is about inserting into the database.

    as for your html you didn't do much with <form> atleast add action
    Seriously kid.. he didn't ask what the hell you thought about his HTML, if you haven't noticed.. the title is Not adding to DB [PHP]

    PHP! PHP! damn.

    oh and get rid of $insert = ...why is that there in the first place!!??!
    Because it is a query! You can get results from queries, server response, and do way more as well as fetch the array sent in an insert.

    There is nothing wrong with that..

    All in all.. you just got owned... quit providing advice.. noob.

    ----------------
    HELP
    ----------------


    change your $insert to this:

    PHP Code:
    $insert mysql_query"INSERT INTO `users` (`username`,`password`,`email`,`ip`,`joindate`,`jointime`) VALUES ('" $username "','" $password "','" $email "','" $ip "','" $date "','" $time "')" ) or die( mysql_error() ); 

    The error probably is in MySQL, but I can't be arsed to check the code.

    That should return a MySQL error for us to look through.

    If that isn't it, try changing to mysql_connect and removing the $link from the mysql_select_db.

  6. #6
    Join Date
    May 2008
    Posts
    605
    Tokens
    0

    Default

    Quote Originally Posted by Hypertext View Post
    Don't use ! in your ternarys, instead just reverse the statements.

    You shouldn't be directly editing data taken from a database ie $logged['in']

    You mispelt mysql_connect

    is $_SESSION['id'] boolean?

    You have a lot of pointless ternarys

    I think your mistaking booleans and wether a string is null/not set

    instead get an ip like $_SERVER['REMOTE_ADDR']

    single quotes are faster than doubles

    your mistaking your variable names (time types) (just a personal preference)

    $logged['in'] should be set as true or false, not 1 or 0.

    I personally wouldn't use a mysql connection resource in your database selector

    I don't know where your going with the output buffering

    a few personal preferences but some are needed.

    please check your code in a debugger or an ide, coming on here asking about mysql_pconnect, it's to be honest wasting everybodys time when you could see that individual mistake in quarter of a second on an ide or a debugger.


    ok your first page

    ips are dynamic a lot of the time so don't use them


    your database schema looks bad - ip - as a row?

    ++$error;
    is faster than
    $error++

    Use echo equals like <?= $var ?>

    where are some of your functions coming from?

    such as is_valid_email




    HOW THE HECK ARE YOU DOING ALL THIS WITHOUT A SINGLE ERROR TO PRODUCE FOR US?



    Wow...

    as for your html you didn't do much with <form> atleast add action


    oh and get rid of $insert = ...why is that there in the first place!!??!
    Mod, please delete this post. Will, if you get an error post it here.

  7. #7
    Join Date
    Dec 2007
    Posts
    1,683
    Tokens
    0

    Latest Awards:

    Default

    I won't bother quoting your post caleb, it's long, but I agree as your code is right etc.

    Add to your form code; (Top of your form, replace the FORM tag)
    HTML Code:
    <form action="" method="post">

  8. #8
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Dentafrice View Post
    I suggest that everyone read this Quite funny. heh.



    Okay, don't be stupid.. you don't know anything about coding.

    After reading your post.. and seeing your stupid remarks about what you think, I have to laugh.. :eusa_clap good job.. it was all a joke right?

    Sadly not with you.. you are actually being serious.. you think what you just said was correct.

    No.. no it wasn't.

    Lets start off with some of the things you just said, and address why they are the most idiotic remarks about PHP I think I have heard yet.

    About as bad as someone asking what echo does.



    Why do that, and increase the file size and coding.. that is not the preferred method.. use !=, but not !$statement.



    Why not? It Isn't editing it on the database.. just the array it is stored on. It is his data.. it is checking the array, not the database..

    Not the safest method, but it works for what he is doing.. duh.



    Why would you have an id with letters?



    getenv is the opposite of using a superglobal.. my god read php.net



    No.. single quotes are for simple strings.. there is no use having a bunch of:

    PHP Code:
    $string 'hey ' $there ' my name is ' $caleb ' I hope ' $you ' ...'
    That is stupid when you can just use a set of "" and be done with it, as PHP parses that string above as each '' being a different string, then joins them.

    So use '' for simple things

    PHP Code:
    $string 'hello'
    "" for variables and other things.. different times for different things..

    don't start going about speeds... you have no clue.



    Haha.. this is my favorite! My absolute favorite.

    Mr. PHP MAN!

    TRUE/FALSE is 1/0!!!!!!

    I thought you knew all this? All true false is, is a boolean!

    So you are telling him to be setting it to the same thing, are you stupid?

    Don't give advice if you don't know what you are talking about.

    You are trying too hard to be smart.



    Okay dude.. listen.. this isn't a normal mysql connect, it is a pconnect, you normally need a link for it to communicate right as it is persis.

    You want to keep it on the same link! Not start another connection, then you run into problems with MySQL taking up 200MB of RAM.

    Gah.



    Maybe if you read?



    He is gzipping it! Congratulations for not reading 6th line.

    He is probably using cookies.. you need ob_start(); :rolleyes:



    You don't need an IDE, it makes it easier yes, but he isn't to the point now where he needs a professional development tool.

    From what I have read, you are on about the same level as him, and neither do you.

    It's to be honest you are wasting everyone's time when you come on here providing wrong advice, wrong coding tips, and stupid points.

    mysql_pconnect is a function to connect to the database.. it isn't ******* mispelled.

    You really need to use PHP.net..



    No **** sherlock, you just figured out the internet?

    What other identifying variable do you suggest we use then..? There isn't one, which is why sites log IPs.

    You could use hostname, which just transfers to an IP and vise versa, or include a shockwave movie and grab the MAC id but that is too much of a pain.

    Which is why we use IPs. Gah.



    Yeah, he is storing the IP.. dip****, the ip isn't a row.. it is a column..

    He is either storing the IP when registered, or constantly updating it.. why would you think it is a row?



    It is the SAME thing.. just reversed.. you are telling it to do the same thing.. it is neither faster or slower.. before making a statement.. test it out.. time it.. god.



    No.. just no.. that is an awful way to do it.. <? is a shortag, do it the right way if you are going to be telling him how to do it.

    You are going to make him a bad as you.

    [php
    <?php echo $var; ?>
    [/php]

    Simple Put it in your clipboard, or snippets, easy as heck.



    Probably a file he hasn't posted, thought of that?



    All your statements are invalid, so there is no 'doing all this'.

    If you haven't noticed.. it isn't about the PHP.. it is about inserting into the database.



    Seriously kid.. he didn't ask what the hell you thought about his HTML, if you haven't noticed.. the title is Not adding to DB [php]

    PHP! PHP! damn.



    Because it is a query! You can get results from queries, server response, and do way more as well as fetch the array sent in an insert.

    There is nothing wrong with that..

    All in all.. you just got owned... quit providing advice.. noob.

    ----------------
    HELP
    ----------------


    change your $insert to this:

    PHP Code:
    $insert mysql_query"INSERT INTO `users` (`username`,`password`,`email`,`ip`,`joindate`,`jointime`) VALUES ('" $username "','" $password "','" $email "','" $ip "','" $date "','" $time "')" ) or die( mysql_error() ); 
    The error probably is in MySQL, but I can't be arsed to check the code.

    That should return a MySQL error for us to look through.

    If that isn't it, try changing to mysql_connect and removing the $link from the mysql_select_db.
    What the hell was that orgasm about?
    Chill pill alert.
    Seriously Caleb, have you even heard about something called benchmarks, the stuff I said is faster is faster because it is. And your thing about <?= ?> is just plain funny. Your the noob!, noob.
    How could this hapen to meeeeeeeeeeeeeee?lol.

  9. #9
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    *removed*

    Edited by SyrupyMonkey (Forum Super Mod.): Please don't be rude to other members.
    Last edited by myke; 23-07-2008 at 04:49 PM.


    www.fragme.co = a project.

  10. #10
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Quote Originally Posted by Hypertext View Post
    What the hell was that orgasm about?
    Chill pill alert.
    Seriously Caleb, have you even heard about something called benchmarks, the stuff I said is faster is faster because it is. And your thing about <?= ?> is just plain funny. Your the noob!, noob.
    Quit using terms in which you do not even know the definition of, you don't even know what benchmarks or benchmarking is, or how to even complete a succesful, accurate benchmarking test.

    You really don't have any idea about PHP, how it works, and what it is based on?

    I have been coding far longer then you, and I know far more then you, if I remember correctly.. you asked me what a class is.. and that was around May, and in almost two months you know what I have learned in years, no...

    Quit pretending you know what you are talking about.. it is getting old.

    I know what the **** a benchmark is, don't talk to me like I'm stupid.. when you don't even know what one is.

    It is not "faster because it is", no.. you don't even know what PHP is doing when it interprets the code.. you don't know what memory it is using, the overhead from using different functions and different methods is all the same.

    Quit pretending..

    I would love to see how you think my statement about <?=$test; ?> is just "plain funny", *removed*

    Edited by SyrupyMonkey (Forum Super Moderator): Please don't be rude, thanks.
    Last edited by myke; 23-07-2008 at 04:51 PM.

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •