简体   繁体   中英

What should form action=“???” on a signup page?

Okay, so I programmed this code, referencing various websites. I'm trying to program a signup page for a website. How does the html form connects to the PHP/how do I connect it?

I know that one place I have messed up is the action="" in the form. Different websites have told me to put different things in, from the server name ("localhost"), to "" to the name of the file that the php is in (I want to do it in the same file as the form if that is possible, I tried both that and a separate file). What do I put in there so when submit is clicked, it gives the error messages on the same screen as the form, and when submit is clicked and there are no error messages, it continues? Where do I link the page it continues on to?

Also, tell me if any of my code is deprecated. I've been trying to check everything, but I could of missed something.

<?php
include 'connect.php';


//if submit is clicked
if (isset($_POST['submit'])) {
    //then check if all fields are filled
    if (!$_POST['username'] | !$_POST['password'] | !$_POST['firstname'] | !$_POST['MI'] | !$_POST['lastname'] | !$_POST['email'] | !$_POST['phonenumber'] | !$_POST['country'] ) {
        die('You did not complete all of the required fields'); }

    $usernamesquery = mysql_query("SELECT * FROM logins WHERE username='$usernametest'");
    if(mysqli_stmt_num_rows($usernamesquery) > 0) {
        die('This username is already taken.');
    }


}

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

Username: <input type="text" name="username" maxlength="30"><br>
Password: <input type="password" name="password" maxlength="30"><br>
First Name: <input type="text" name="firstname" maxlength="30"><br>
Middle Initial: <input type="password" name="MI" maxlength="30"><br>
Last Name: <input type="text" name="lastname" maxlength="30"><br>
Email: <input type="password" name="email" maxlength="50"><br>
Phone Number: <input type="text" name="phonenumber" maxlength="11"><br>
Country: <input type="password" name="country" maxlength="40"><br>
<input type="submit">
</form>

If you want it to direct to the same file, then just use:

<form action="" method="POST">

Also there is no $_POST["submit"] since you haven't given your submit button a name.

<input type="submit" name="submit">

Also, does $usernametest actually contain anything? Since you haven't given it a value in your code above.

The "action" is page with some script, that parse the form data and do the login.

For example: the form has action "login.php", that means after you submit the form, the data are sent to "login.php" where you can acces it via $_POST variable. If you have login logic and form in the same file, you don't have to set any action, it's ok if you do it like this

<form action="" method="POST">

More info here

If you want to submit the form to the same page (the URL you are allready on), you can just leave out the action from the <from> tag. Otherwise, you specify the URL (relative or absolute) the form needs to be submitted to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM