Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2012
    Posts
    27
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Some help with user registration pls!!

    Hi everyone so I have a problem with my code it registers the user but inserts only the username password and email.
    I have other fields like cellphone, phone, fax and location please see below code and advise.
    The fist one is the html form.
    <code>
    <html>
    <body>
    <form action="register.php" method="post">
    Username: <input name="name" type="text" />
    Surname: <input name="surname" type="text" />
    Password: <input type="password" name="password" />
    Email: <input name="email" type="text" />
    Cellphone: <input name="cell" type="text" />
    Phone: <input name="phone" type="text" />
    Fax: <input name="fax" type="text" />
    Location: <input name="location" type="text" />
    <input type="submit" value="Submit" />
    </body>
    </html>
    </code>

    This is the register.php code
    <php>
    <?php
    include("db.php");
    if (isset($_POST['name']) && isset($_POST['surname']) && isset($_POST['password']) && isset($_POST['email'])
    && isset($_POST['cell']) && isset($_POST['phone']) && isset($_POST['fax']) && isset($_POST['location']))

    {
    //Prevent SQL injections
    $name = mysql_real_escape_string($_POST['name']);
    $email = mysql_real_escape_string($_POST['email']);


    //Get MD5 hash of password
    $password = md5($_POST['password']);

    //Check to see if username exists
    $sql = mysql_query("SELECT name FROM userReg1 WHERE name = '".$name."'");
    if (mysql_num_rows($sql)>0)
    {
    die ("Username taken.");
    }


    mysql_query("INSERT INTO userReg1(name, surname, password, email, cell, phone, fax,
    location) VALUES ( '$name', '$surname', '$password', '$email', '$cell', '$phone', '$fax',
    '$location' )")
    or die (mysql_error())
    ; echo ("Account created.");

    }
    ?>
    </php>

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Code:
    //Prevent SQL injections 
    $name = mysql_real_escape_string($_POST['name']); 
    $email = mysql_real_escape_string($_POST['email']);
    You haven't set these variables for $cell, etc..

    Pl. surround your code examples in [ CODE ] [/ CODE ] tags (without the spaces) or, specific for PHP, [ PHP ] [ /PHP ].
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #3
    New Coder
    Join Date
    Feb 2012
    Posts
    27
    Thanks
    2
    Thanked 0 Times in 0 Posts
    That should not be the problem since those variables does not write to the database.
    But I tried it anyway but still no luck.

  • #4
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Your OP was about the values for cellphone, phone etc. not be inserted into your database:

    Hi everyone so I have a problem with my code it registers the user but inserts only the username password and email.
    I have other fields like cellphone, phone, fax and location please see below code and advise.
    And your query attempts to insert these values, but you haven't defined the corresponding variables:

    PHP Code:
    mysql_query("INSERT INTO userReg1(name, surname, password, email, cell, phone, fax,
    location) VALUES ( '$name', '$surname', '$password', '$email', '$cell', '$phone', '$fax',
    '$location' )"
    )
    or die (
    mysql_error())

    So I'm at a loss as to what you are asking
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • Users who have thanked AndrewGSW for this post:

    Hein (08-13-2012)

  • #5
    New Coder
    Join Date
    Feb 2012
    Posts
    27
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Ok cool thanx you were right!
    That was the problem!
    Now my next issue is the auto invoicing system!


  •  

    Posting Permissions

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