1

Hey guys i have a problem basically i made a script in php which connects to a database. But when i try and send the data to the database it does not go into the data base even though it says thank you for signing up. But when i add the info and check to see if its in the database its not. Can someone please solve my problem thank you :)

<?php
$submitcheck = @$_POST['submit'];
$fullnameCheck = strtolower(strip_tags(@$_POST['fullname']));
$LastNameCheck = strtolower(strip_tags(@$_POST['Lastname']));
$UserNameCheck = strip_tags(@$_POST['username']);
$PasswordCheck = strip_tags(@$_POST['password']);
$ReCheckPass = strip_tags(@$_POST['repassword']);
$date = date("Y-m-d");

if ($submitcheck) {

    // connect to the database
    // checking data 

    if ($PasswordCheck && $ReCheckPass && $UserNameCheck && $fullnameCheck && $LastNameCheck) {


        if ($PasswordCheck == $ReCheckPass) {


            //Check length of username and password

            if (strlen($UserNameCheck) > 25) {

                echo "Username must be less than 25 characters";
            } else {

                if (strlen($LastNameCheck) > 25) {

                    echo "Last name must be less thank 25 charcters";
                } else {

                    if (strlen($fullnameCheck) > 25) {

                        echo "Your Fisrt name is too long must be less than 25";
                    } else {

                        if (strlen($PasswordCheck) > 25 || strlen($PasswordCheck) < 6) {


                            echo "Password must be between 6 to 25";
                        } else {

                            //register the user 
                            $PasswordCheck = md5($PasswordCheck);
                            $ReCheckPass = md5($ReCheckPass);

                            $connect = mysql_connect("localhost", "root", "halo123");
                            mysql_select_db('phplogin');

                            $namecheckers = mysql_query("SELECT * FROM users WHERE username ='$UserNameCheck'");
                            $counts = mysql_num_rows($namecheckers);

                            if ($counts != 0) {

                                die("username in use sorry");
                            }

                            $queryreg = mysql_query("INSERT INTO users()id, username, password, FisrtName, LastName, date) VALUES ('id','$UserNameCheck','$PasswordCheck','$fullnameCheck','$LastNameCheck','$date')");

                            die("Congrats you have been registered <a href='test.php'>Click here</a> to return to login page");
                        }
                    }
                }
            }
        }
        else
            echo "your passwords do not macth";
    }
    else
        echo "Please fill in all the information thank you ";
}
?>


<html


    <head>
    <p>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
        <title>Register</title>




    </head>

<body>

    <form action='register.php' method="POST" >

        Fisrt Name: <input type="text" name="fullname" value="<?php echo $fullnameCheck; ?>"/><br />

        Last Name: <input type="text" name="Lastname" value="<?php echo $LastNameCheck; ?>"/><br />

        Chose Username: <input type="text" name="username" value="<?php echo $UserNameCheck; ?>"/><br />

        Chose Password: <input type="password" name="password" /><br />

        repeat Password: <input type="password" name="repassword" /><br />
        <input type="submit" name ="submit" value="register"/>

    </form>



</body>


</html>
3
  • did you run this query to make sure it works with test data? "INSERT INTO users()id, username, password, FisrtName, LastName, date) VALUES ('id','$UserNameCheck','$PasswordCheck','$fullnameCheck','$LastNameCheck','$date')" Commented Mar 11, 2012 at 23:55
  • 2
    Every time I see @ in PHP, my face does the same :@. You should look into using isset() Commented Mar 11, 2012 at 23:59
  • add or die(mysql_error()) at the end of your mysql_query, and you will see what the actual error is Commented Mar 12, 2012 at 3:56

2 Answers 2

3
INSERT INTO users()id, username, password, FisrtName, LastName, date) VALUES ('id','$UserNameCheck','$PasswordCheck','$fullnameCheck','$LastNameCheck','$date'‌​)

Surely should be:

INSERT INTO users(id, username, password, FisrtName, LastName, date) VALUES ('id','$UserNameCheck','$PasswordCheck','$fullnameCheck','$LastNameCheck','$date'‌​)
Sign up to request clarification or add additional context in comments.

4 Comments

i fixed that one but thats not the problem as well :) and the fisrt name was a mistake lol i changed that but still it makes no difference :(
Well you also have 'id' in the values, should this not be an auto-increment field or at least an int?
yea :) i removed that as well it was set as my primary key lol can i send you my folder and see if you can fix it for me please :)
Why don't you just do an insert into the DB using phpMyAdmin, grab the query which it runs then compare this to the query you are putting together. Then you should easily be able to see where this is going wrong by comparing them against each other. Sending me your files will not be of use really as you need to be debugging against the DB. Maybe post the table schema?
1

You need to check the result of mysql_query to see if the query actually worked. The code as you have it now assumes it works and ignores any error that may have occurred.

If mysql_query returns FALSE, you can check the error with mysql_error()

2 Comments

Hey i tried the error for mysql and this is what is says Warning: mysql_error() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\PhpLearn\register.php on line 79 Congrats you have been registered Click here to return to login page
Please check out the documentation of mysql_error() at php.net/manual/en/function.mysql-error.php (especially example #1), that should help you along.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.