programmierfrage.com
Ask a question    Sign Up Sign In
  • Train typing speed
  • About/Contact
  • Privacy Policy
  1. Home
  2. Basic php Login form with defined Name and Password

479 votes
2 answers

Basic php Login form with defined Name and Password

Get the solution ↓↓↓
Closed. This question needs debugging details. It is not currently accepting answers.

Undefined asked
2022-11-26
Write your answer



78
votes

Answer

Solution:

The first time you run this script, the$_POST['username'] (and password) isn't defined.

What you have to do is check if it's defined like this:

if(isset($_POST['username']) && $_POST['username'] == "user" && isset($_POST['password']) &&  $_POST['password']=="user")

Here's an link about the isset function

Also, do the check on top of the page. Because you'r already sending content, your redirect won't work.

header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP

Write your answer




391
votes

Answer

Solution:

First check that you really have some $_POST data:

if (!empty($_POST)) {
    // then check your username and password
    if($_POST['username'] =="user" && $_POST['password']=="user")
    {
        header("Location: contact.php");
    }
    else 
    {
        // display error
    }
}
Write your answer




Share solution ↓

Additional Information:

Date the issue was resolved:
2022-11-26
Link To Source
Link To Answer People are also looking for solutions of the problem: ftp_put(): can't open that file: no such file or directory

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Similar questions

Find the answer in similar questions on our website.

726 html - Can't get rid of blank php page after submission form
496 PHP function to get needed values form array
988 Using PHP have a MySQL statement into multiple PHP variables
852 php - Laravel 5 - inserting old data into form via variable
899 php - Wrong email password
278 php - converting from mysql to PDO username confirmation issue
9 .htaccess - PHP - URL with multiple parameters and same name causing unexpected behaviour
724 Eclipse PDT PHP + HTML Formatter is not aligned?
914 php - Wordpress - Default and Post Name URL Permalink
880 php - Laravel 5.3 relationship returns wrong one

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.






About the technologies asked in this question

PHP

PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites. The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/


HTML

HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet. Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/



Welcome to programmierfrage.com

programmierfrage.com is a question and answer site for professional web developers, programming enthusiasts and website builders. Site created and operated by the community. Together with you, we create a free library of detailed answers to any question on programming, web development, website creation and website administration.

Get answers to specific questions

Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.

Help Others Solve Their Issues

Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.



Latest questions:

320 php - Laravel 5 syntax error, unexpected 'extends' (T_EXTENDS)

797 mysql - PHP - mysqli - check the table if a value is already inserted

604 mysql - Change Database records sort order to move record position in between other records with PHP

662 javascript - Get XML from PHP to Jquery - XML tags

925 php - set og tags for homepage only

95 php - file_get_contents not working on the server but working fine on local machine

97 php - Using Zend tableGateway to INSERT on one table and UPDATE another

130 php - converting from mysql to PDO username confirmation issue

956 php - Using Faker in Laravel 5.0 returns 'Class User not found'

687 javascript - How to display returned json using jquery ajax

Users questions:

NEW

Rename existing images with keyword in WordPress PHP

NEW

codeigniter

NEW

Class "web_profiler.controller.profiler" does not exist after upgrading symfony 3.4 to 4.4 version

NEW

$charge = \Stripe\Charge::create(array( "amount" => 100, "currency" => "gbp", "source" => $token, "destination" => [ "amount" => 20, "account" => 'xxxxx', ], ));

NEW

Write a PHP program that will generate the JSON structure below. Second Step: Write a JAVASCRIPT program that will parse the JSON structure once the PHP program is called using AJAX. You may show your output on the body of the HTML document or in the console




PHP x 410847
Laravel x 36785
Yii x 3846
CodeIgniter x 9997
Symfony x 7793
CakePHP x 3085
Zend Framework x 1235
Phalcon x 300
FuelPHP x 47
Slim x 570
JavaScript x 36883
React x 550
Angular x 1121
Vue.js x 181
JQuery x 11108
Backbone.js x 21
Node.js x 463
Ember.js x 10
Meteor x 7
Polymer x 20
Aurelia x 1
MySQL x 39074
CSS x 2497
Bootstrap x 1603
Foundation x 84
UIkit x 4
Semantic UI x 2
Bulma x 2
Animate.css x 1
HTML x 20978



© 2021-2023 Programming problem solving site for beginners and advanced. Answers to questions related to coding.

E-mail: [email protected]

This site uses cookies. We use them to improve the performance of our website and your interaction with it. Confirm your consent by clicking OK


OK