daveh24706 Posted February 8, 2010 Share Posted February 8, 2010 hello, im new to php,only at it a week and im writing a registration script. I cant figure out what im doing wrong. When i enter my details and click register nothing happens and its just goes back to original register form. i dont even get an error message. my code is below. <?php // set a submit variable $submit = $_POST['submit']; // other values that need to be obtained from the form $fullname = $_POST['fullname']; $username = $_POST['username']; $password = $_POST['password']; $repeatpassword = $_POST['repeatpassword']; $date = date("y-m-d"); $email = $_POST['email']; if ($submit) { //Open database $connect = mysql_connect("localhost","root",""); mysql_select_db("phplogin");//select database $namecheck = mysql_query("SELECT username FROM users WHERE username='$username'"); $count = mysql_num_rows($namecheck); if($count!=0) { die("Username already taken!"); if ($fullname&&$username&&$password&&$repeatpassword&&$email) { if ($password==$repeatpassword) { if (strlen($username)>25 || strlen ($fullname)>25) { echo "username/fullname is too long. Max 25 characters"; } else { if (strlen($password) >25 || strlen ($password) <6) { echo "password must be between 6 and 25 characters"; } else { //register the user $queryreg = mysql_query("INSERT INTO users VALUES ('','$fullname','$username','$password','$email')"); die ("you have been registered! <a href='index.php'>return to login page </a>"); } } } else echo "your passwords do not match"; } else echo "please fill in all fields"; } } ?> Quote Link to comment Share on other sites More sharing options...
jl5501 Posted February 8, 2010 Share Posted February 8, 2010 do you have a hidden field on your form called 'submit' or is the button itself called 'submit' Quote Link to comment Share on other sites More sharing options...
daveh24706 Posted February 8, 2010 Author Share Posted February 8, 2010 well the button is called register <input type='submit' name='submit' value='Register'> Quote Link to comment Share on other sites More sharing options...
jl5501 Posted February 8, 2010 Share Posted February 8, 2010 no it is called submit, which is fine, so that is not your problem Quote Link to comment Share on other sites More sharing options...
corrupshun Posted February 8, 2010 Share Posted February 8, 2010 I know your problem, where you have $submit = $_POST['submit']; and then if ($submit) if checks to see if it is true or false, what your putting inside it is if(submit), which won't do anything. I am assuming your making it check to see if the person submitted the page, use this: <?php if(isset($_POST['submit'])) { //do register stuff } else { //show register form } ?> And as a side note, what you have here is VERY insecure, so i'm hoping your not uploading that script somewhere. It's open to SQL Injection. Quote Link to comment Share on other sites More sharing options...
daveh24706 Posted February 8, 2010 Author Share Posted February 8, 2010 ok, so i replace $submit = $_POST['submit']; with if(isset($_POST['submit'])) i dont think i fully understand, i did this put still the same problem Quote Link to comment Share on other sites More sharing options...
corrupshun Posted February 8, 2010 Share Posted February 8, 2010 get rid of the submit variable, you won't be using it. replace: if ($submit) with if(isset($_POST['submit'])) this checks to see if submit is set. If it is set then it will produce 'true', if it's not true, it will be false. The 'if' statement checks to see if the condition is true or false. that's ALL it checks. If you still need more help look up booleans Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.