Results 1 to 8 of 8

Thread: register script problem

  1. #1
    Join Date
    Jan 2012
    Posts
    21
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Unhappy register script problem

    well I have this problem with my script:
    couldn't insert data!

    well I use this check error message inside my code after the checking if data is inserted inside database or not.
    anyway the code has two part html,php
    the html is used to handle form and show registration process and the php to handle the registration part.
    the data base I have called fleet at my localhost server with this table users, users has rows (id,username, password, firstname,lastname,dat_reg)
    sorry for taking too long to explain everything but I need help to resolve the database error shown at top
    here html file code:
    HTML Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Registration Page</title>
    <link rel="stylesheet" href="stylesheets/foundation.css">
    <link rel="stylesheet" href="stylesheets/app.css">
    <link rel="stylesheet" href="formly.css">
    </head>
    
    <body>
    <div class="row">
    <h1>Registration page</h1><br/><br/>
    
    <form action='register.php' method='post' class="nice" id="ContactInfo" >
    			
                <label>Enter Username:</label>
            	<input type='text' name='username' class="medium input-text" />
            	<label for="password">Enter Password:</label>
            	<input type='password' name='password' class="medium input-text" title="Try to make it hard to guess."/>
            	<label>Repeat Password:</label>
            	<input type='password' name='repeatpassword' class="medium input-text"/>
            	<label>Enter firstname:</label>
            	<input type='text' name='firstname' class="medium input-text"/>
            	<label>Enter lastname:</label>
            	<input type='text' name='lastname' class="medium input-text"/>
            <input type='submit' name='submit' value='register' class="white radius nice button"/>
           
    </form>
    </div>
    </body>
    </html>
    and the register.php code:
    PHP Code:

    <?php
        
    //include("config.php");
    //form data for registration
        
    $firstname strip_tags($_POST['firstname']);
        
    $lastname strip_tags($_POST['lastname']);
        
    $username strtolower(strip_tags($_POST['username']));
        
    $password strip_tags($_POST['password']);
        
    $repeatpassword strip_tags($_POST['repeatpassword']);
        
    $date = ("y-m-d");
        
    $submit $_POST['submit'] ;
        if(isset(
    $submit)){
        if(
    $firstname&&$username&&$password&&$repeatpassword){
            
    //check if password = repeatpassword
            
    if($password == $repeatpassword){
                    
    //check username length
                    
    if(strlen($username)>25||strlen($username)<3){
                        echo
    "the allowed username length between 3 and 25!";
                        }
    //end username check length
                        //start else for username length
                        
    else{
                            
    //checking password length
                            
    if(strlen($password)>25||strlen($password)<5){
                                echo
    "your password must be between 5 and 25!";
                                }
    //end checking password length
                                //start else for checking password length
                                
    else{
                                    
    //encrypt the passwords
                                    
    $password md5($password);
                                    
    $repeatpassword md5($repeatpassword);
                                    
    $connectmysql_connect("localhost","root","")or die("could not connect database!");
                                    
    mysql_select_db("fleet",$connect)or die("couldn't select database!");
                        
    $queryreg "INSERT INTO users (id,username,password,firstname,lastname,date_reg) VALUES ('0','".$username."','".$password."','".$firstname."','".$lastname."','".$date."')";
                                    
                                    
    mysql_query($queryreg $connect)or die("couldn't insert data!");
                                    echo 
    "registration sucessful! back to member page <a 'href='member.php'>here</a>";
                                    }
    //end else for checking password length
                            
    }//end else for username length
                
    }//end check if password = repeatpassword
                
    else{
                    echo
    "password and repeatpassword not match!";
                    }
        }
    //end of checking fields
        
    else
            echo
    "Please fill in all feilds!";
        }

        
    ?>

  2. #2
    Join Date
    Jan 2012
    Location
    India
    Posts
    45
    Thanks
    12
    Thanked 1 Time in 1 Post

    Default

    this is working fine, check again or may be you mis spelled your table name.

  3. #3
    Join Date
    Jan 2012
    Posts
    21
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    well I don't know if it good or not, but what I'm sure the wrong part of my code only at the query part so I've double check the database table and test with phpmyadmin its working but inside this code isn't why that what I wish to know!!

  4. #4
    Join Date
    Jan 2012
    Posts
    21
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    I found the problem now its wit $dat var when I delete it from both database and use comment the problem solved:
    //$date = ("y-m-d");
    but I wish to know how to make this var working so I could know when the user register, I read about it at php.net but it hard for me to understand how to make insert this kind of data inside the database and what I should use as row type.

  5. #5
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    is your dat_reg field a DATETIME type? If so, Y-m-d is not a valid format. You need to use a format like YYYY-MM-DD HH:MM:SS.

    alternatively, if all you want is the current date/time, use mysql's NOW() function (or UTC_TIMESTAMP(), which is beneficial if you deal with multiple timezones).

  6. #6
    Join Date
    Jan 2012
    Posts
    21
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    thank you very much for those information anyway if I want to do this dat_reg set at mysql database as DATETIME type then use this var:
    $date = "YYYY-MM-DD HH:MM:SS";
    then use this query:
    $queryreg = "INSERT INTO users (id,username,password,firstname,lastname,date_reg) VALUES ('0','".$username."','".$password."','".$firstname."','".$lastname."','".$date."')"
    does it going to work and what the data will show in database field if you can show me I really appriciate your help cause still facing problem with the date type I was use in date_reg DATE type but doesn't work with $date = "y-m-d";

  7. #7
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    a few options:
    PHP Code:
    <?php
    // this gives you a MySQL timestamp based on the current time _on_your_server_
    //  (this is how to do it according to your current approach)
    $date date'Y-m-d H:i:s' );
    $query "INSERT INTO `table` (`date`) VALUES ('$date')";

    // this gives you a MySQL timestamp based on the current time _on_your_database_server_
    $query "INSERT INTO `table` (`date`) VALUES (NOW())";

    // this gives you a MySQL timestamp based on the current _utc_time_
    //  (this is usually the best option: 
    //   you can reliably compare times that came from different timezones, 
    //   and you can still interpret the date to your local timezone when you need to.)
    $date date'Y-m-d H:i:s' );
    $query "INSERT INTO `table` (`date`) VALUES (UTC_TIMESTAMP())";

  8. The Following User Says Thank You to traq For This Useful Post:

    hosam (01-27-2012)

  9. #8
    Join Date
    Jan 2012
    Posts
    21
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    thank you very much for those great information now I could do it correctly and know the user date of registration I also add thank

Bookmarks

Posting Permissions

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