+ Reply to Thread
Results 1 to 5 of 5

Thread: Why doesn't this save to my mysql file? (PHP)

  1. #1
    garrette is offline x10Hosting Member garrette is an unknown quantity at this point
    Join Date
    Jan 2012
    Posts
    27

    Why doesn't this save to my mysql file? (PHP)

    It worked literally 15 minutes before, and I tried to make a small change to the script, erased it because I changed my mind, and now it won't save this information to my database. . . any idea why?

    PHP Code:
    <?php
    //form data
    $submit $_POST['submit'];
    $Name strip_tags($_POST['Name']);
    $username strip_tags($_POST['username']);
    $password strip_tags($_POST['password']);
    $repeatpassword strip_tags($_POST['repeatpassword']);
    $email $_POST['email'];
    $repeatemail $_POST['repeatemail'];
    $date date("Y-m-d");


    if (
    $submit)
    {

        
    //opens the database
            
    $connect mysql_connect('localhost',"******","*******");
            
    mysql_select_db('********'); //Selects the database
            
            
    $namecheck mysql_query("SELECT username FROM users WHERE username='$username'");
            
    $count mysql_num_rows($namecheck);
            
            if (
    $count!=0)
            {
            die(
    "Username is already taken, sorry!");
            }
            
            
    $emailcheck mysql_query("SELECT email FROM users WHERE email='$email'");
            
    $check mysql_num_rows($emailcheck);
            
            if (
    $check!=0)
            {
            die(
    "This email is already taken, sorry!");
            }
     
    //Makes sure the fields are filled
    if ($Name&&$username&&$password&&$repeatpassword&&$email&&$repeatemail)
    {
        
        if (
    $password==$repeatpassword//Makes sure the passwords are the same.
        
    {
            
    //Check character length of user name.
            
    if (strlen($username)>25||strlen($Name)>25)
            {
                echo 
    "Max length of username and your name are 25 characters.";
            }
            
            else 
    //Checks the password length
            
    {
            if (
    strlen($password)>25||strlen($password)<6)
            {
            
            echo 
    "Password must be between 6 and 25 characters.";
            }
            else 
            
            
    //Encrypts the passwords.
            
    $password md5($password);
            
    $repeatpassword md5($repeatpassword);
            
            
    //Checks the email lenth
            
    if (strlen($email)>30||strlen($email)<10)
            {
            echo 
    "Your email must be between 10 and 30 characters.";
            }
            
            else 
    //Registers the user.
            
            
    $queryreg mysql_query("INSERT INTO users VALUES (' ','$Name','$username','$password','$email','$date'");
        
            echo 
    "You have been registered! <br><a href='**********'> Return to the login page</a>.";

            }
        
        }
        else
            echo 
    "Your passwords do not match!";
    }
    else
        echo 
    "Please fill in all the fields";


    }
    ?>
    It won't add it to my tables, therefore it won't create user accounts. I have no idea why either. Anyone have any ideas?

  2. #2
    Skizzerz's Avatar
    Skizzerz is offline Contributors Skizzerz will become famous soon enough
    Join Date
    Nov 2007
    Location
    Texas
    Posts
    2,153

    Re: Why doesn't this save to my mysql file? (PHP)

    An error message would be helpful if you are getting one.

    Also, please note that the PHP mysql extension has been deprecated by the PHP group, due to various issues with it. A common issue with it is the fact that it leaves users to write insecure scripts. For example, there is nothing stopping me from submitting an email address with a SQL injection in it, because you fail to escape that input properly. A common rule of thumb to use is to "escape every input and sanitize every output" that involves user-generated information.

    Also, what is the point behind limiting the maximum password length to 25? If there is a maximum, it should be much higher than that.

    Otherwise, I can't help you much without an error message. If misson or essellar happen to pop in, I suggest you heed everything they say.
    Last edited by Skizzerz; 01-05-2012 at 06:20 PM.
    Ryan Schmidt | Level 2 Support
    █ 888-X10-9668 - ryan[@]x10hosting.com
    x10Hosting - Giving Away Hosting Since 2004
    Premium Hosting | VPS Services

  3. #3
    garrette is offline x10Hosting Member garrette is an unknown quantity at this point
    Join Date
    Jan 2012
    Posts
    27

    Re: Why doesn't this save to my mysql file? (PHP)

    I have fixed the problem, it was within the database. I don't remember what exactly I did, but I did get it working.

    As for the SQL injection, how to I stop this insecurity? I am using a tutorial from 2009 to help with learning the mysql extensions, but that is probably according to what you are saying.

    Do you possibly have a resource that could show me what I should do?

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

    Re: Why doesn't this save to my mysql file? (PHP)

    Quote Originally Posted by garrette View Post
    As for the SQL injection, how to I stop this insecurity? [...] Do you possibly have a resource that could show me what I should do?
    See my previous post(s), which also cover other generic mistakes that happen to appear in the sample code in this thread. The key is to use prepared statements (and an extension that supports them).

    One issue that I haven't covered in your code (but have in many other threads on these forums) is the insecure password storage scheme. MD5 is considered broken by security professionals. No less than Bruce Schneier has written:
    But -- come on, people -- no one should be using MD5 anymore.
    Use a newer hashing function, such as whirlpool or something from the SHA2 family (SHA256, SHA512) or (better still) Blowfish (using crypt(). Your password scheme is also vulnerable to rainbow tables. Add salt to fix this. You could use the username + a system salt, or (better still) give each user a unique salt (a "nonce") and store that in a column in table `users`.

    Quote Originally Posted by garrette View Post
    I am using a tutorial from 2009 to help with learning the mysql extensions, but that is probably according to what you are saying.
    The mysql extension became outdated in 2004, when mysqli was included with PHP 5.0.0, and again in 2005 when PDO was incorporated into PHP 5.1.0 from the PECL package (with PHP 5.0, the server admin could install PDO as an optional package). You could consider it outdated even before that, considering programmer installable packages such as Pear::DB.
    Last edited by misson; 01-06-2012 at 03:35 AM.
    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.

  5. #5
    garrette is offline x10Hosting Member garrette is an unknown quantity at this point
    Join Date
    Jan 2012
    Posts
    27

    Re: Why doesn't this save to my mysql file? (PHP)

    Thanks for the information! I will be sure to look into all of this! Very helpful.

+ Reply to Thread

Similar Threads

  1. Error: Cannot save file to harddrive
    By xterranut in forum Free Hosting
    Replies: 0
    Last Post: 10-03-2011, 09:23 AM
  2. MySQL Username and Database do not save
    By itsme95959595 in forum Free Hosting
    Replies: 3
    Last Post: 06-26-2010, 06:59 PM
  3. Word cannot save due to a file permission error
    By Teensweb in forum Computers & Technology
    Replies: 9
    Last Post: 09-28-2008, 05:17 PM
  4. 150c for custom userbar save file
    By mike16889 in forum The Marketplace
    Replies: 4
    Last Post: 05-13-2008, 11:52 PM

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