Victor Njoroge
Victor Njoroge

Reputation: 353

isset function not working on same page as form

When I use the isset() function when data is posted from another PHP page it works fine. But when I use the isset() function in the same page to process a form it does not post the data. I see the data in the url but the isset() does not seem to work. The form stays empty and nothing happens.

Here is the form I am currently working on:

<h3>Register</h3>

<?php 
   if(isset($_POST["register_email"],$_POST["register_name"],$_POST["register_password"]))      
   {
       $register_email=$_POST['register_email'];
       $register_name=$_POST['register_name'];
       $register_password=$_POST['register_password'];

       $errors=array();

       if(empty($register_email) || empty($register_name) || empty($register_password))
       {
           $errors[]='All fields required';
       } 

       if(!empty($errors))
       {
           foreach($errors as $error)
           {
               echo $error,'<br />';
           }
       } 
       else {
           echo 'ok';
       }
   }
?>

<form action="" method="">
    <p>Email: <br /><input type="email" name="register_email" size="35" maxlength="255"></p>
    <p>Full name: <br /><input type="text" name="register_name" maxlength="35"></p>
    <p>Password: <br /><input type="password" name="register_password" maxlength="35"></p>
    <p><input type="submit" value="Register"></p>
</form>

Upvotes: 1

Views: 1758

Answers (2)

AreRex14
AreRex14

Reputation: 47

In case of mine,just set for one only,in this case the name of input to register and isset to register.isset will refer to the name of input

if(isset($_POST["register"])) input type="submit" value="Register" name="register">

Upvotes: 0

Niclas Larsson
Niclas Larsson

Reputation: 858

I think you have forgotten to set the form's method to post:

<form action="" method="post">

Upvotes: 7

Related Questions