Results 1 to 2 of 2

Thread: Register script not working (php)

  1. #1
    Join Date
    Mar 2006
    Posts
    4

    Register script not working (php)

    for the past few days, ive been trying to make a login script for my website...

    ive been trying to troubleshoot it. Whenever i try to creat a user it tells me "couldnt add data to table". I have no idea what to do, i tried manualy putting in the sql querry without php and it worked. Im not sure whats wrong. ill post the scripts too.
    PHP Code:
    this is the register2.php script


    <?php

    $username 
    $_POST['username'];
    $password $_POST['password'];
    $email $_POST['email'];
    $ip $REMOTE_ADDR;
    $username strip_tags($username);
    $email strip_tags($email);
    $password md5($password);
    //form check
    if ( !$username || !$password ) {
        die( 
    "You did not enter a username or password" );
    }
    //mysql login
    $sqluser "dbuser";
    $sqlpass "dbpw";
    $db "mydb";
    $connect mysql_connect"localhost"$sqluser$sqlpass );
    if ( ! 
    $connect ) {
        die( 
    "Could not connect to SQL server" );
    }
    mysql_select_db$db$connect )
    or die (
    "Could not open database:" .mysql_error() );
    //check if user exists
    $selectstatement "SELECT * FROM users WHERE username='$username'";

    //insert data into db
    $insertstatement "INSERT INTO users ( username, password, email, ip ) VALUES (
    '
    $username', '$password', '$email', '$ip' )";

    $result mysql_query$selectstatement$connect );
    $numrows mysql_num_rows$result );
    if ( 
    $numrows ) {
        print 
    " The username you have chosen is in use. Please choose another one.";
    }
    else {
        
    mysql_query$insertstatement$connect )
                or die( 
    "Couldn't add data to table" );
        print 
    "Registration successful! ";
    }
    ?>
    PHP Code:

    this is the register
    .php script (forms only)

    <
    html>
    <
    head><title>Temporary registry</title></head>
    <
    body align="center">
    <
    form action="register2.php" method="post">
    Username: <input type="text" name="username" size="20"><br>
    Password: <input type="password" name="password" size="20"><br>
    Email: <input type="text" name="email" size="30"><br>
    <
    center><input type="submit" value="Submit"><input type="reset"></center>
    </
    form>
    </
    body>
    </
    html

  2. #2
    Join Date
    Apr 2006
    Posts
    74
    Are you sure you have the mySQL username, password and database name correct?
    Also, consider changing the code to:
    PHP Code:
     mysql_query$insertstatement$connect )
                or die( 
    "Couldn't add data to table<br/>".mysql_error()); 
    to get a better idea of what's going wrong...

Posting Permissions

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