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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP registration form issue

    Hello, I recently started learning php and i want to create a simple php registration form for my website. I cant seem to find what i did wrong, but whenever i run the script, it gives a error/blank screen and doesn't add anything to my database.

    PHP Code:
    <?php
    $host
    ="sql208.phpnet.us";
    $username="";
    $password="";
    $db_name="pn_12690608_bioweb";
    $tbl_name="account_data";

    $conn=mysql_connect($host$username$password)or die("cannot connect");
    mysql_select_db($db_name,$conn)or die("cannot select DB");

    $username=_$POST[username]; 
    $password=_$POST[password]; 
    $first=_$POST[first]; 
    $last=_$POST[last]; 
    $email=_$POST[email]; 

    mysql_query("INSERT INTO
    account_data
    (first,last,username,password,email)
    VALUES
    ('$first','$last','$username',
    '$password','$email')"
    );
    ?>
    I broke up the last part about mysql_query because it wont show in 1 line for some reason, its supposed to be in 1 line
    2 minutes ago

    The registration form:

    Code:
    <form id="register" name="registration_form" method="post" action="registration_script.php">
    Username:<input id="username" name="username" type="text">
    
    Password:<input id="password" name="password" type="password">
    
    First Name:<input id="first" name="first" type="text">
    
    Last Name:<input id="last" name="last" type="text">
    
    Email:<input id="email" name="email" type="text">
    
    <input type="submit" value="Submit" name="submit">
    </form>
    Last edited by Inigoesdr; 03-30-2013 at 01:53 PM.

  • #2
    Regular Coder
    Join Date
    Jun 2009
    Posts
    134
    Thanks
    3
    Thanked 19 Times in 19 Posts
    1st thing, you need to sanitize your data before putting it into the DB, look up SQL injection

    2nd add an or die to the INSERT query to see if you get more info on what is failing.

    Its $_POST not _$POST, and place the items in parenthesis, like $_POST['username']

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Also make sure you read our stickies for important information such as the FAQ section that talks about getting a blank page and the sticky about putting your code in [PHP][/PHP] tags.

  • #4
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Finnally got it to work! Thanks itxtme!
    @Inigoesdr Sorry about the messy code, I will make sure i put it in [php] tags next time!


  •  

    Posting Permissions

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