Bman900 Posted April 13, 2010 Share Posted April 13, 2010 So I am following this tutorial on registering but it must have been coded in PHP4 because am getting different errors in PHP5. Here is what I have: $username = strip_tags($_POST['username']); $password = strip_tags($_POST['password']); $repeatpassword = strip_tags($_POST['repeatpassword']); $email = strip_tags($_POST['email']); $date = date("Y-m-d"); if(isset($_POST['submit'])) { And here is the errors it throws up: Notice: Undefined index: username in C:\wamp\www\mysite\register.php on line 32 Notice: Undefined index: password in C:\wamp\www\mysite\register.php on line 33 Notice: Undefined index: repeatpassword in C:\wamp\www\mysite\register.php on line 34 Notice: Undefined index: email in C:\wamp\www\mysite\register.php on line 35 This I understand because the first time you load the page there are no values in those variables but if I were to put that in my if statement I can not use those variables in my Form code as I want the information to stay within the form if an error message is thrown up. Here is the whole block of code that shows the form code as well and how I have it set up. <?php $username = strip_tags($_POST['username']); $password = strip_tags($_POST['password']); $repeatpassword = strip_tags($_POST['repeatpassword']); $email = strip_tags($_POST['email']); $date = date("Y-m-d"); if(isset($_POST['submit'])) { //check if all fields are filled in if($username&&$password&&$repeatpassword&&$email) { //check if passwords match if ($password==$repeatpassword){ //check character lenght if (strlen($username)>18 || strlen($username)<4){ echo "User names must be within 4-18 characters. <a href=\"register.php\">Go Back</a>"; } else { //check password lenght if(strlen($password)>15 || strlen($password)<6){ echo "Password must be within 6 to 15 characters! <a href=\"register.php\">Go Back</a>"; } //register user else { echo "Success!!"; } } } // error if passwords do not match else { echo "Your passwords do not match, please go back and try again! <a href=\"register.php\">Go Back</a>"; } } //error if fields are not field in else { echo "Please fill in all field before proceeding! <a href=\"register.php\">Go Back</a>"; } } ?> <form action='register.php' method="post"> <table> <tr> <td> Username: </td> <td> <input type='text' name='username' value =' <?php echo $username; ?>' /> </td> </tr> <tr> <td> Password: </td> <td> <input type='password' name='password' /> </td> </tr> <tr> <td> Repeat Password </td> <td> <input type='password' name='repeatpassword' /> </td> </tr> <tr> <td> Email: </td> <td> <input type='text' name='email' value='<?php echo $email; ?>' /> </td> </tr> </table> <p> <input type="submit" name="submit" value="Submit" /> </form> Link to comment https://forums.phpfreaks.com/topic/198425-form-error/ Share on other sites More sharing options...
Pikachu2000 Posted April 13, 2010 Share Posted April 13, 2010 Just move them inside the if( isset($_POST['submit']) ) { } conditional. There's no reason for them to be outside of it anyhow. Link to comment https://forums.phpfreaks.com/topic/198425-form-error/#findComment-1041257 Share on other sites More sharing options...
Bman900 Posted April 13, 2010 Author Share Posted April 13, 2010 Yea I had to do that and I did if statements inside the value='' and worked like a charm! Link to comment https://forums.phpfreaks.com/topic/198425-form-error/#findComment-1041260 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.