+ Reply to Thread
Results 1 to 7 of 7
Like Tree2Likes
  • 1 Post By wtvelocity
  • 1 Post By misson

Thread: Registration Submit shows code

  1. #1
    wtvelocity is offline x10Hosting Member wtvelocity is an unknown quantity at this point
    Join Date
    Jun 2008
    Posts
    9

    Registration Submit shows code

    I'm trying to program a PHP registration script, but when I click submit, it ends up DISPLAYING register.php instead of processing it.

    Register.htm
    Code:
    <?php include('vdaemon.php'); ?>
    <HTML>
    <BODY>
    <form name="login" method="post" action="register.php">
    <table border="0" width="225" align="center">
        <tr>
            <td width="219" bgcolor="#999999">
                <p align="center"><font color="white"><span style="font-size:12pt;"><b>Registration</b></span></font></p>
            </td>
        </tr>
        <tr>
            <td width="219">
                <table border="0" width="282" align="center">
                        <tr>
                            <td width="116"><span style="font-size:10pt;">Name:</span></td>
                            <td width="156"><input type="text" name="name" maxlength="100"></td>
                        </tr>
                        <tr>
                            <td width="116"><span style="font-size:10pt;">Email:</span></td>
                            <td width="156"><input type="text" name="email" maxlength="100"></td>
                        </tr>
                    <tr>
                        <td width="116"><span style="font-size:10pt;">Username:</span></td>
                        <td width="156"><input type="text" name="username"></td>
                    </tr>
                    <tr>
                        <td width="116"><span style="font-size:10pt;">Password:</span></td>
                        <td width="156"><input type="password" name="password"></td>
                    </tr>
                    <tr>
                        <td width="116">&nbsp;</td>
                            <td width="156">
                                <p align="right"><input type="submit" name="submit" value="Submit"></p>
                            </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td width="219" bgcolor="#999999">&nbsp;</td>
        </tr>
    </table>
    </form>
    </BODY>
    </HTML>
    Register.php
    Code:
    $dbhost = "localhost";
    $dbname = "wilddog_members";
    $dbuser = "wilddog";
    $dbpass = "(password)";
    
    mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
    mysql_select_db($dbname) or die(mysql_error());
    
    
    $name = $_POST['name'];
    $email = $_POST['email'];    
    $username = $_POST['username'];
    $password = $_POST['password'];
    
    
    
    $name = $_POST['name'];
    $email = $_POST['email'];    
    $username = $_POST['username'];
    $password = md5($_POST['password']);
    
    
    $checkuser = mysql_query("SELECT username FROM users WHERE username='$username'");
    
    $username_exist = mysql_num_rows($checkuser);
    
    if($username_exist > 0){
        echo "I'm sorry but the username you specified has already been taken.  Please pick another one.";
        unset($username);
        include 'register.html';
        exit();
    }
    
    
    $query = "INSERT INTO users (name, email, username, password)
    VALUES('$name', '$email', '$username', '$password')";
    mysql_query($query) or die(mysql_error());
    mysql_close();
    
    echo "You have successfully Registered";
    
    $yoursite = ‘ConquestOfAges.elementfx.com’;
    $webmaster = ‘Christian Darwin’;
    $youremail = ‘admin@conquestofages.exofire.com’;
    
    $subject = "You have successfully registered at $yoursite...";
    $message = "Dear $name, you are now registered at our web site.  
        To login, simply go to our web page and enter in the following details in the login form:
        Username: $username
        Password: $password
        
        Please print this information out and store it for future reference.
        
        Thanks,
        $webmaster";
        
    mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());
        
    echo "Your information has been mailed to your email address.";
    ?>
    Thanks for your time!
    Last edited by wtvelocity; 04-07-2010 at 04:22 PM. Reason: Security, and adding code
    dinomirt96 likes this.

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Registration Submit shows code

    Well, I now know your DB password by viewing that code.
    Nothing is always absolutely so.

  3. #3
    wtvelocity is offline x10Hosting Member wtvelocity is an unknown quantity at this point
    Join Date
    Jun 2008
    Posts
    9

    Re: Registration Submit shows code

    DO'OH!

    Thanks for pointing that out, editing my post

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Registration Submit shows code

    Forget the opening <?php ??
    Nothing is always absolutely so.

  5. #5
    wtvelocity is offline x10Hosting Member wtvelocity is an unknown quantity at this point
    Join Date
    Jun 2008
    Posts
    9

    Re: Registration Submit shows code

    Thanks, but now I got this error:


    Parse error: syntax error, unexpected '=' in /home/wilddog/public_html/register.php on line 46

    I don't see it X(

  6. #6
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Registration Submit shows code

    PHP Code:
    $yoursite ‘ConquestOfAges.elementfx.com’;
    $webmaster ‘Christian Darwin’;
    $youremail ‘admin@conquestofages.exofire.com’
    You used funky quotes. ' or " only.
    Nothing is always absolutely so.

  7. #7
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Registration Submit shows code

    Quote Originally Posted by wtvelocity View Post
    Register.php
    PHP Code:
    $name $_POST['name'];
    $email $_POST['email'];    
    $username $_POST['username'];
    $password $_POST['password'];
    ...
    $checkuser mysql_query("SELECT username FROM users WHERE username='$username'");
    ...
    $query "INSERT INTO users (name, email, username, password)
    VALUES('
    $name', '$email', '$username', '$password')";
    mysql_query($query) or die(mysql_error()); 
    This is vulnerable to SQL injection. You can escape the input values to prevent this, but the more modern and simpler approach is to use prepared statements (note: only parameters in prepared statements are invulnerable to SQL injection). Read "Writing MySQL Scripts with PHP and PDO" for more information on using the PDO driver (which has better support for prepared statements than mysqli).

    Displaying the output of mysql_error() to users discloses too much information; it's both a security risk and doesn't offer users anything useful.
    karimirt47 likes this.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Javascript submit to form submit
    By e85andyou in forum Programming Help
    Replies: 2
    Last Post: 11-03-2008, 08:33 AM
  2. POST without submit
    By zester in forum Programming Help
    Replies: 23
    Last Post: 07-14-2008, 03:22 PM
  3. Replies: 1
    Last Post: 05-27-2008, 09:31 PM
  4. un able to submit Score
    By Palito in forum Introductions
    Replies: 6
    Last Post: 12-30-2007, 08:25 AM
  5. Problems with Registration system [PHP Code included]
    By Jarryd in forum Scripts & 3rd Party Apps
    Replies: 0
    Last Post: 11-24-2007, 05:38 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers