jamesyrawr Posted August 6, 2010 Share Posted August 6, 2010 i seem to get the following errors: Notice: Undefined index: submit in C:\wamp\www\registration\register.php on line 12 Notice: Undefined index: fullname in C:\wamp\www\registration\register.php on line 14 Notice: Undefined index: username in C:\wamp\www\registration\register.php on line 15 Notice: Undefined index: password in C:\wamp\www\registration\register.php on line 16 Notice: Undefined index: repeat_password in C:\wamp\www\registration\register.php on line 17 its only in the php section that i am getting them <?php //Form Data echo "<h1>Registration</h1>"; $submit = $_POST['submit']; $fullname = $_POST['fullname']; $username = $_POST['username']; $password = $_POST['password']; $repeat_password = $_POST['repeat_password']; if ($submit) { } ?> <html> <form action='register.php' method='POST'> <table> <tr> <td> Choose a Username: </td> <td> <input type='text' name="username"> </td> </tr> <tr> <td> Password: </td> <td><input type='password' name="password"> </td> </tr> <tr> <td> Repeat Your Password: </td> <td><input type='password' name="repeat_password"> </td> </tr> <tr> <td> Your Full Name: </td> <td><input type='text' name="name"> </td> </tr> </table> <p><input type='submit' name='submit'></p> </form> </html> Quote Link to comment Share on other sites More sharing options...
bh Posted August 6, 2010 Share Posted August 6, 2010 Hi, Use isset to decide is the variable is set and not null. Eg like this: if (isset($_POST['submit'])) { } Quote Link to comment Share on other sites More sharing options...
jamesyrawr Posted August 6, 2010 Author Share Posted August 6, 2010 thanks for your reply but i'm still getting the same errors below is the altered code Notice: Undefined index: submit in C:\wamp\www\registration\register.php on line 12 Notice: Undefined index: fullname in C:\wamp\www\registration\register.php on line 14 Notice: Undefined index: username in C:\wamp\www\registration\register.php on line 15 Notice: Undefined index: password in C:\wamp\www\registration\register.php on line 16 Notice: Undefined index: repeat_password in C:\wamp\www\registration\register.php on line 17 <?php//Form Data echo "<h1>Registration</h1>"; $submit = $_POST['submit']; $fullname = $_POST['fullname']; $username = $_POST['username']; $password = $_POST['password']; $repeat_password = $_POST['repeat_password']; if (isset($_POST['submit'])) { } ?> Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 6, 2010 Share Posted August 6, 2010 2 options if(isset($_POST['submit']){ $submit = $_POST['submit']; $fullname = $_POST['fullname']; $username = $_POST['username']; $password = $_POST['password']; $repeat_password = $_POST['repeat_password']; } //OR //Looks complex but I will explain $fullname = isset($_POST['fullname']) ? $_POST['fullname'] : ''; $username = isset($_POST['username']) ? $_POST['username'] : ''; //Same for the rest //Now that is short hand if statements // Basically ? is IF the condition is TRUE then : is the Else // so $username = isset($_POST['username']) ? $_POST['username'] : ''; //is the same as if(isset($_POST['username']){ $username = $_POST['username']; }else{ $username = ''; } Quote Link to comment Share on other sites More sharing options...
jamesyrawr Posted August 6, 2010 Author Share Posted August 6, 2010 thanks for the reply i have a new error now i tried the second version you made and it still has errors in <?php echo "<h1>Registration</h1>"; if(isset($_POST['submit']) $fullname = isset($_POST['fullname']) ? $_POST['fullname'] : ''; $username = isset($_POST['username']) ? $_POST['username'] : ''; $password = isset($_POST['password']) ? $_POST['password'] : ''; $repeat_password = isset($_POST['repeat_password']) ? $_POST['repeat_password'] : ''; if (isset($_POST['submit'])) { } ?> ihave attached a picture to show what my piece of software is saying Thanks James [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted August 6, 2010 Share Posted August 6, 2010 Take a look: if(isset($_POST['submit']) No parenthesis... You also don't need this: if (isset($_POST['submit'])) { } Because you're doing nothing there. Above you have the checks for the variables. Preferably, I'd re-think how you're going about it. Use the first option. if(isset($_POST['submit']){ $fullname = $_POST['fullname']; $username = $_POST['username']; $password = $_POST['password']; $repeat_password = $_POST['repeat_password']; // Do stuff with form data, validate. Then register. } 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.