473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

checking fields of log in form

My question is simple.

When a user types in a blank username or password, I want to say sorry, you must enter a username and a password in a different colour.

Can someone suggest how to do this. I thought I woiuld be able to find something quick online, but either everything seems too complicated or I just cannot find what I want.
Jul 2 '07 #1
1 996
kovik
1,044 Expert 1GB
That's simple enough for me to give a straight answer to.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(!empty($_POST)) // Form has been submitted
  3. {
  4.     if(!isset($_POST['username'], $_POST['password']))
  5.     {
  6.         $error = "You must fill in all fields.";
  7.     }
  8.     else
  9.     {
  10.         // Submit and process the data
  11.     }
  12. }
  13. ?>
  14.  
  15. <form method="post" action="" >
  16.     <input type="text" name="username" value="<?php
  17.     echo isset($_POST['username']) ? $_POST['username'] : '';?> />
  18.     <input type="password" name="password" value="<?php
  19.     echo isset($_POST['password']) ? $_POST['password'] : '';?> />
  20.     <input type="submit" value="Submit" />
  21. </form>
That should do it. Inform me if there are any typos.


You just have to check each form field (which you should ALWAYS do anyway).
Jul 2 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dariusz | last post by:
I have a small form that on button press submits to a PHP file for further processing into a database. I have to change the script as it allows blank / nothing to be submitted to the database. ...
3
by: Antoni | last post by:
Hello I wondered if this script seemed correct? The user should enter a userid and password in two text fields, and then pass these values to the method login_user. Could I ask, is there any...
2
by: Alistair | last post by:
hey peoples. I have a simple form (currently two fields) which is then passed to an ASP page thats stores the data in a dbase I have an error checking script which I can't get to work. the...
3
by: Jack | last post by:
Hi, I have a form when loaded, retrieves record from an access table. Among other fields there is a check box called FinalUpdate. This is tied to a field in Access of type Yes/No. The form...
2
by: Gawie Marais | last post by:
hi all, i have a form and would like to check two fields. if field 1 containes the letter 'c' and the other field contains 'undefined', then an error should apprear ina box on the screen. can...
4
by: reinhout | last post by:
Hi everyone, I have made a script that checks if content is entered in the html boxes and if the required fields are empty, their border lights red. This all works, but if I try to make a...
2
by: fperri | last post by:
Hi, I have a table with over 20 columns. Seven of these of these columns correspond to a filter on a search form. Based on what is selected on the search form, and what is in these seven fields in...
6
by: maxx429 | last post by:
I am trying to check if notes have been added to a Memo field on a form if certain other fields have changed. Example: If the user ticks a particular check box on the form, I want to force them to...
7
by: john.cole | last post by:
I have searched all the groups I can, and I still haven't been able to come up the solution I need. I have the following problem. In my form named sbfrmSpoolList, I am entering a job, spool and...
1
by: geetamadhavi | last post by:
Hi All, I have developed a php applciaiton where a new window is opening on checking the whether valid user orntot how to make that in same window after checking i have die(' not valid user ' ); i...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.