Chi
Chi

Reputation: 43

I cannot post html input to php

I'm pretty new to using html and php, and its my first time building a website. I'm trying to use php to have users create accounts on my website. Here is my html code.

<form action="postinfo.php" method="post">
        <table border="0">
          <tr>
              <td>First Name:</td>
              <td align="center"><input type="text" name="firstname" size="20" /></td>
          </tr>
          <tr>
              <td>Last Name:</td>
              <td align="center"><input type="text" name="lastname" size="20" /></td>
          </tr>
          <tr>
              <td>Email Address:</td>
              <td align="center"><input type="text" name="emailaddress" size="20" /></td>
          </tr>
          <tr>
              <td>Username:</td>
              <td align="center"><input type="text" name="username" size="20" /></td>
          </tr>
          <tr>
              <td>Password:</td>
              <td align="center"><input type="password" name="password" size="20" /></td>
          </tr>
          <tr>
              <td>Confirm Password:</td>
              <td align="center"><input type="password" name="repassword" size="20" /></td>
          </tr>
          <tr>
              <td colspan ="2" align="center"><input type="submit" name="submit" value="submit" /></td>
          </tr>
        </table>
    </form>

Here is my php code,

<!DOCTYPE html>
<html>
    <head>
        <title>signupinfo</title>
    </head>

    <body>
        <p>Account information</p>
        <?php
            if (isset($_POST["submit"])) {
                $firstname = $_POST['firstname'];
                $lastname = $_POST['lastname'];
                $emailaddress = $_POST['emailaddress'];
                $username = $_POST['username'];
                $password = $_POST['password'];
                $repassword = $_POST['repassword'];
            }

            echo $firstname . ["</br>"];
            echo $firstname . ["</br>"];
            echo $firstname . ["</br>"];
            echo $firstname . ["</br>"];
            echo $firstname . ["</br>"];
        ?>

    </body>

</html>

when I click the submit button, it says Cannot POST /postinfo.php

is there an issue with formatting the code? I have no idea how to solve it. Please help me. Thanks.

Upvotes: 1

Views: 585

Answers (1)

Giulio Bambini
Giulio Bambini

Reputation: 4755

In php [] is an array. And you tried to echo an array. This is the main reason for not working. Try this code

<?php
        if (isset($_POST["submit"])) {
            $firstname = $_POST['firstname'];
            $lastname = $_POST['lastname'];
            $emailaddress = $_POST['emailaddress'];
            $username = $_POST['username'];
            $password = $_POST['password'];
            $repassword = $_POST['repassword'];

            echo $firstname . "</br>";
            echo $firstname . "</br>";
            echo $firstname . "</br>";
            echo $firstname . "</br>";
            echo $firstname . "</br>";            

        }
    ?>

Before use this code make sure about the correct action url.

Upvotes: 1

Related Questions