Results 1 to 6 of 6

Thread: Inserting in register information please help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    104

    Unhappy Inserting in register information please help

    Here i am trying to insert a query for register the user in my site

    any body can tell me dat wts the mistake is there

    PHP Code:
    <?php
    require("settings.php");
    // Register information 
    if ($_POST['submit']!="") {
        if(
    $_POST['userid']!=""){
            if (
    $_POST['username'] != "") {
                if (
    $_POST['password'] != "") {
                    
    $userid mysql_real_escap_string($_POST['userid']);
                    
    $username mysql_real_escape_string($_POST['username']);
                    
    $password mysql_real_escape_string($_POST['password']);
                    echo 
    $userid;
                    echo 
    $username;
                    echo 
    $password;
                    
                    
    $password md5($password);//To stroe the password in md5
                    
    $sql =(" INSERT INTO 'users' (userID, username, password) VALUES('$userid','$username,'$password') ");
                    
    $query mysql_query($sql);
                    echo 
    "Register Successful";
                    } 
                    else {
                        echo 
    "Register Failed";
                    }
                    }
                        else {
                            echo 
    "Please enter username";
                        }
                    
                    }
                        else {
                            echo 
    "please enter the password";
                        }
                    }
                    
                    
    ?>
    <html>
    <body>
    <font color="#FF0000"></font>  
    <form action="register.php" method="post"> <br>
    Userid:<input type="text" name="userid"><br>
    Username:<input type="text" name="user"><br>
    Password:<input type="password" name="pass"><br>
    <input type="submit" name="Register" value="Register" ><br>
    </body>
    <html>
    Please help me

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Inserting in register information please help

    I can see where your mistake is. But I am not going to tell you . How about posting the error message you receive and we can work on how find it yourself.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Inserting in register information please help

    I think visualAd is trying to get you to learn how to debug your code, so I am not going to spoil that.

    In that code there are 5 problems...

    There is 1 fatal error, 2 errors in the SQL query and 2 problems with the logic.

    If you are not getting an error message, then turn errors on using
    PHP Code:
    error_reporting(E_ALL); 
    Or look in the access log for the error. When you do see the error, it should be obvious what the problem is.

    When you have solved the fatal error which is halting the script. You can then look at solving the problems in the SQL query. If a MySQL query is not doing what it is supposed to, you can get the error message using the mysql_error() function like so:
    PHP Code:
    echo mysql_error(); 
    As for the logic, I don't know how anyone can easily read your logic with those if/else statements written like that, you should tab them properly.

    The first logic problem I see is you are echoing "registration failed" if the password is blank. That's not an accurate error message, it should be like your others "please enter a password".

    Secondly, you are echoing "Registration successful" after the query, regardless of the result.... that means if the query failed, your program will still tell the user it was successful. You can put an if statement around the $query variable to check if it failed or not, and then you can give the user that information e.g.
    PHP Code:
    $query mysql_query($sql);

    if(
    $query)
    {
       
    //success
    }
    else
    {
       
    //failed

    Lastly, you have a lot of echo statements with error messages, why not put the message in a $msg variable and just use one echo statement at the end. This way you can add HTML markup to the echo without having to go through all of your echo statements.
    Chris

  4. #4
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Inserting in register information please help

    I see the error as well. Also, i notice that you are echoing the userid, password, and username before they are sent to the db ( and before the password is md5'ed). My first guess is that you are attempting to debug. If not, then i would remove at least password and userid, and put something like "Thanks for registering USERNAME"
    Last edited by dclamp; Nov 15th, 2008 at 12:50 PM.
    My usual boring signature: Something

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    104

    Re: Inserting in register information please help

    yeah thanx i got it

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Inserting in register information please help

    Quote Originally Posted by the182guy
    I think visualAd is trying to get you to learn how to debug your code, so I am not going to spoil that.
    I wasn't trying to say that; I was trying to help him do it, but you spoiled that.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width