Home > Back-end >  PHP Post Method Not Doing Anything - Will Only Work When Styling Is Gone
PHP Post Method Not Doing Anything - Will Only Work When Styling Is Gone

Time:07-21

Cannot seem to get this working - Will only work with styling gone. Is there any reason why I cannot get it to working whilst styling is left in? Are there any particular settings I need to change? I've tried most things suggested online, but it still wont work. I've been at this for hours now.

<?php

if(isset($_POST['register'])) {
    echo "Working";
}


?>

<form method="post" action="register.php">
    <div >
        <div >
            <div >
                <input  id="inputFirstName" type="text" placeholder="Enter your first name" />
                <label for="inputFirstName">First name</label>
            </div>
        </div>
        <div >
            <div >
                <input  id="inputLastName" type="text" placeholder="Enter your last name" />
                <label for="inputLastName">Last name</label>
            </div>
        </div>
    </div>
    <div >
        <input  id="inputEmail" type="email" placeholder="[email protected]" />
        <label for="inputEmail">Email address</label>
    </div>
    <div >
        <div >
            <div >
                <input  id="inputPassword" type="password" placeholder="Create a password" />
                <label for="inputPassword">Password</label>
            </div>
        </div>
        <div >
            <div >
                <input  id="inputPasswordConfirm" type="password" placeholder="Confirm password" />
                <label for="inputPasswordConfirm">Confirm Password</label>
            </div>
        </div>
    </div>
    <div >
        <div >
            <a  type="submit" name="register" id="register"> Create Account</a>
        </div>
    </div>
</form>

</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
<script src="js/scripts.js"></script>
</body>
</html>

CodePudding user response:

You have to fix small mistake to make it run. For example

Wrong:

<a  type="submit" name="register" id="register"> Create Account</a>

Right:

<input  type="submit" name="register" id="register" value="Create Account">

OR

<button  type="submit" name="register" id="register"> Create Account</button>

You can use A Tag to submit a form but that is totally different thing. This post will help you in case you want it: a tag as a submit button?

Here is the complete working version of your code

<?php

if(isset($_POST["register"])) {
    echo "Working";
}


?>

<form method="post" action="">
    <div >
        <div >
            <div >
                <input  id="inputFirstName" type="text" placeholder="Enter your first name" />
                <label for="inputFirstName">First name</label>
            </div>
        </div>
        <div >
            <div >
                <input  id="inputLastName" type="text" placeholder="Enter your last name" />
                <label for="inputLastName">Last name</label>
            </div>
        </div>
    </div>
    <div >
        <input  id="inputEmail" type="email" placeholder="[email protected]" />
        <label for="inputEmail">Email address</label>
    </div>
    <div >
        <div >
            <div >
                <input  id="inputPassword" type="password" placeholder="Create a password" />
                <label for="inputPassword">Password</label>
            </div>
        </div>
        <div >
            <div >
                <input  id="inputPasswordConfirm" type="password" placeholder="Confirm password" />
                <label for="inputPasswordConfirm">Confirm Password</label>
            </div>
        </div>
    </div>
    <div >
        <div >
            <button  type="submit" name="register" id="register"> Create Account</button>
        </div>
    </div>
</form>

</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
<script src="js/scripts.js"></script>
</body>
</html>

CodePudding user response:

  1. First of all, replace the label tags with input tags. These do not cause any problems, just the way you wrote is unusual and irregular.

  2. Second, you have to write the register button with the button or input tag, and this is your main problem.

or

<button  type="submit" name="register" id="register"> Create Account</button>
  • Related