1

For my very simple registration page, I designed a very simple code for registration:

  • one textfield to enter the desired registration name
  • and one button to submit it and run the phpscript which connects to sql

But for some reason the button is dead. Clicking on it doesnt do anything.

If i enter a name however and press enter w. keyboard, the code runs fine...

what am i missing?

thank you in advance for your help!!

<form action="#" method="post">
        <div class="register">
                <input type="text" placeholder="username" name="name" class="field required" />
                <input type="button" value="register" />                
        </div></form>

<?php if(!empty($_POST['name'])): ?>
.
.
.
go on
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141

2 Answers2

3

You need to declare your button as 'submit', instead of 'button'.

Instead of

<input type="button" value="register" />

declare it this way

<input type="submit" value="register" />

A submit type input does exactly what comes to your mind when you read it - it submits the form. You can have multiple buttons within your form, but it is a good practice to keep only one submit button whose job is to send the form information wherever needed.

Please read some of the following HTML guides to get a better understanding on how things need to be done:

https://www.w3schools.com/html/html_forms.asp

https://www.w3schools.com/html/html_form_input_types.asp

Tommy Naidich
  • 752
  • 1
  • 5
  • 23
  • 1
    While these links may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Jay Blanchard Apr 19 '17 at 13:04
  • @JayBlanchard I have mentioned the exact problem with OP's code, along with a simple but clear explanation on what needs to be changed. – Tommy Naidich Apr 19 '17 at 13:06
  • 1
    I understand that. I have given you the guidelines for your answer to be a ***good answer***. Link only answers are generally considered "bad" by the community. – Jay Blanchard Apr 19 '17 at 13:07
  • @JayBlanchard Why giving guidelines for a good answer if my answer falls under these guidelines in the first place? This isn't a "link only answer". – Tommy Naidich Apr 19 '17 at 13:15
  • I am just trying to help you Tommy. I didn't say you had to take my advice. – Jay Blanchard Apr 19 '17 at 13:17
  • @TommyNaidich copy paste google research are generally considered "bad" by the community , so for that i would like to invite you to modify your answer – Achref Gassoumi Apr 19 '17 at 13:20
  • Personally, I don't see the relevance for the HTML references. There should have been references for forms (and inputs). You're basically having them to *look" for the forms references in those pages. Having used direct links to the forms in addition to what you included, would have made this better. However, and as already stated by @JayBlanchard - Link only answers have been discussed on meta and here's a Q&A about it https://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers – Funk Forty Niner Apr 19 '17 at 13:32
  • I'm always glad to take advice and criticism when one is given, but given the fact my answer was clear enough at that point, adding anything on top of that felt like spoon-feeding to me. Regardless, it has been updated. – Tommy Naidich Apr 19 '17 at 13:32
  • 1
    @Fred-ii- good point, I'm setting more specific links in my answer. – Tommy Naidich Apr 19 '17 at 13:33
  • Again Tommy, as @JayBlanchard stated above, we're just trying to help you provide better answers; we're not *attacking* you and hope you don't take this personally. – Funk Forty Niner Apr 19 '17 at 13:34
  • 1
    @Fred-ii- I wasn't feeling attacked at any point, just wanted to make things clear. Thanks for your input. – Tommy Naidich Apr 19 '17 at 13:35
2

You just need to change the button type to submit. See this working example:

<form action="#" method="post">
        <div class="register">
                <input type="text" placeholder="username" name="name" class="field required" />
                <input type="submit" value="register" />                
        </div></form>

<?php if(!empty($_POST['name'])): ?>
.
.
.
go on
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
freginold
  • 3,946
  • 3
  • 13
  • 28