473,503 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Varifying Forms Text Data Help Needed

I bought the PHP and MySQL For Dummies book and I'm having trouble
understanding how I use PHP to verify and check forms input text data
- the book shows snippets of code so I know how to do the actual check
but I don't understand what web page the php checking code should go
into?

For example, I have a simple login web page (username and password)
and then it calls my mainmenu php web page - I want to make a check
that a username was actually typed in *before* calling the mainmenu
php page - I also know that I can do this check using javascript but
I'd like to stay in php if I can - how can I make the check and stay
on this login form before calling the mainmenu page?

Thanks...

Jul 16 '05 #1
4 2493
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Whilst lounging around on Sat, 05 Jul 2003 23:55:02 GMT, Ralph
Freshour <ra***@primemail.com> amazingly managed to produce the
following with their Etch-A-Sketch:
I bought the PHP and MySQL For Dummies book and I'm having trouble
understanding how I use PHP to verify and check forms input text
data - the book shows snippets of code so I know how to do the
actual check but I don't understand what web page the php checking
code should go into?

For example, I have a simple login web page (username and password)
and then it calls my mainmenu php web page - I want to make a check
that a username was actually typed in *before* calling the mainmenu
php page - I also know that I can do this check using javascript
but I'd like to stay in php if I can - how can I make the check and
stay on this login form before calling the mainmenu page?

Thanks...


Assuming you have 'username' and 'password' as your form text fields,
and your method is POST:
<?php
if (!preg_match("/([a-zA-Z_.-]+)/", $_POST['username'])) {
@header('Location: http://' .
$_SERVER['HTTP_HOST'] .
'/login.php'
);
}

if (!empty($_POST['password'])) {
// do check for password match
if (md5($_POST['password']) == $required_password) {
@header('Location: http://' .
$_SERVER['HTTP_HOST'] .
'/mainmenu.php'
);
} else {
die('Invalid login');
}
?>
This isn't a coplete solution as you'll need to fill out the
commented areas, but should do what you're after =)
HTH.

Regards,

Ian

-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0

iQA/AwUBPwdr92fqtj251CDhEQJZ2ACfSxH6N4JBiaHnMl8wIJxL+4 Whfy0AoIfT
8wKHusl/p2M0a6HBdp01qcEb
=g6N7
-----END PGP SIGNATURE-----

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
Jul 16 '05 #2
@header('Location: http://' .$_SERVER['HTTP_HOST'] .'/login.php'

gives me an error:

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING

The PHP Manual gives this syntax for header() but it gives a similar
error:

header("Location:http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/login.php");

I gather this header function check will cause my login.php script
re-display which is what I want when the user leaves it blank and
still clicks on the submit button.

Ralph

On Sun, 06 Jul 2003 00:23:21 GMT, "Ian.H [dS]"
<ia*@WINDOZEdigiserv.net> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Whilst lounging around on Sat, 05 Jul 2003 23:55:02 GMT, Ralph
Freshour <ra***@primemail.com> amazingly managed to produce the
following with their Etch-A-Sketch:
I bought the PHP and MySQL For Dummies book and I'm having trouble
understanding how I use PHP to verify and check forms input text
data - the book shows snippets of code so I know how to do the
actual check but I don't understand what web page the php checking
code should go into?

For example, I have a simple login web page (username and password)
and then it calls my mainmenu php web page - I want to make a check
that a username was actually typed in *before* calling the mainmenu
php page - I also know that I can do this check using javascript
but I'd like to stay in php if I can - how can I make the check and
stay on this login form before calling the mainmenu page?

Thanks...


Assuming you have 'username' and 'password' as your form text fields,
and your method is POST:
<?php
if (!preg_match("/([a-zA-Z_.-]+)/", $_POST['username'])) {
@header('Location: http://' .
$_SERVER['HTTP_HOST'] .
'/login.php'
);
}

if (!empty($_POST['password'])) {
// do check for password match
if (md5($_POST['password']) == $required_password) {
@header('Location: http://' .
$_SERVER['HTTP_HOST'] .
'/mainmenu.php'
);
} else {
die('Invalid login');
}
?>
This isn't a coplete solution as you'll need to fill out the
commented areas, but should do what you're after =)
HTH.

Regards,

Ian

-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0

iQA/AwUBPwdr92fqtj251CDhEQJZ2ACfSxH6N4JBiaHnMl8wIJxL+4 Whfy0AoIfT
8wKHusl/p2M0a6HBdp01qcEb
=g6N7
-----END PGP SIGNATURE-----


Jul 16 '05 #3

"Ralph Freshour" <ra***@primemail.com> wrote in message
news:7k********************************@4ax.com...
@header('Location: http://' .$_SERVER['HTTP_HOST'] .'/login.php'

gives me an error:

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING

The PHP Manual gives this syntax for header() but it gives a similar
error:

header("Location:http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']
)."/login.php");
I gather this header function check will cause my login.php script
re-display which is what I want when the user leaves it blank and
still clicks on the submit button.

Ralph

On Sun, 06 Jul 2003 00:23:21 GMT, "Ian.H [dS]"
<ia*@WINDOZEdigiserv.net> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Whilst lounging around on Sat, 05 Jul 2003 23:55:02 GMT, Ralph
Freshour <ra***@primemail.com> amazingly managed to produce the
following with their Etch-A-Sketch:
I bought the PHP and MySQL For Dummies book and I'm having trouble
understanding how I use PHP to verify and check forms input text
data - the book shows snippets of code so I know how to do the
actual check but I don't understand what web page the php checking
code should go into?

For example, I have a simple login web page (username and password)
and then it calls my mainmenu php web page - I want to make a check
that a username was actually typed in *before* calling the mainmenu
php page - I also know that I can do this check using javascript
but I'd like to stay in php if I can - how can I make the check and
stay on this login form before calling the mainmenu page?

Thanks...


Assuming you have 'username' and 'password' as your form text fields,
and your method is POST:
<?php
if (!preg_match("/([a-zA-Z_.-]+)/", $_POST['username'])) {
@header('Location: http://' .
$_SERVER['HTTP_HOST'] .
'/login.php'
);
}

if (!empty($_POST['password'])) {
// do check for password match
if (md5($_POST['password']) == $required_password) {
@header('Location: http://' .
$_SERVER['HTTP_HOST'] .
'/mainmenu.php'
);
} else {
die('Invalid login');
}
?>
This isn't a coplete solution as you'll need to fill out the
commented areas, but should do what you're after =)
HTH.

Regards,

Ian

-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0

iQA/AwUBPwdr92fqtj251CDhEQJZ2ACfSxH6N4JBiaHnMl8wIJxL+4 Whfy0AoIfT
8wKHusl/p2M0a6HBdp01qcEb
=g6N7
-----END PGP SIGNATURE-----


Try to use double quote instead of single quote:
$_SERVER["HTTP_HOST"]


Jul 16 '05 #4
What is the code flow with this header() function? When I inserted
your suggested header code, the browser web page didn't do anything -
nothing but the loading bar was moving across like it was trying to do
something or was doing something - is this in an endless loop? I
don't understand how this code is 'triggered' - if it is processed
when the login.php script first loads, then username is always blank
since the user hasn't filled it in yet - maybe another way of asking
this question is when does this if statement with the header code
execute? I have it at the top of my .php script.
On Sun, 06 Jul 2003 03:29:30 GMT, "Steven" <xu*****@comcast.net>
wrote:

"Ralph Freshour" <ra***@primemail.com> wrote in message
news:7k********************************@4ax.com.. .
@header('Location: http://' .$_SERVER['HTTP_HOST'] .'/login.php'

gives me an error:

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING

The PHP Manual gives this syntax for header() but it gives a similar
error:

header("Location:http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']
)."/login.php");

I gather this header function check will cause my login.php script
re-display which is what I want when the user leaves it blank and
still clicks on the submit button.

Ralph

On Sun, 06 Jul 2003 00:23:21 GMT, "Ian.H [dS]"
<ia*@WINDOZEdigiserv.net> wrote:
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Whilst lounging around on Sat, 05 Jul 2003 23:55:02 GMT, Ralph
>Freshour <ra***@primemail.com> amazingly managed to produce the
>following with their Etch-A-Sketch:
>
>> I bought the PHP and MySQL For Dummies book and I'm having trouble
>> understanding how I use PHP to verify and check forms input text
>> data - the book shows snippets of code so I know how to do the
>> actual check but I don't understand what web page the php checking
>> code should go into?
>>
>> For example, I have a simple login web page (username and password)
>> and then it calls my mainmenu php web page - I want to make a check
>> that a username was actually typed in *before* calling the mainmenu
>> php page - I also know that I can do this check using javascript
>> but I'd like to stay in php if I can - how can I make the check and
>> stay on this login form before calling the mainmenu page?
>>
>> Thanks...
>
>
>
>Assuming you have 'username' and 'password' as your form text fields,
>and your method is POST:
>
>
><?php
> if (!preg_match("/([a-zA-Z_.-]+)/", $_POST['username'])) {
> @header('Location: http://' .
> $_SERVER['HTTP_HOST'] .
> '/login.php'
> );
> }
>
> if (!empty($_POST['password'])) {
> // do check for password match
> if (md5($_POST['password']) == $required_password) {
> @header('Location: http://' .
> $_SERVER['HTTP_HOST'] .
> '/mainmenu.php'
> );
> } else {
> die('Invalid login');
> }
>?>
>
>
>This isn't a coplete solution as you'll need to fill out the
>commented areas, but should do what you're after =)
>
>
>HTH.
>
>
>
>Regards,
>
> Ian
>
>-----BEGIN PGP SIGNATURE-----
>Version: PGP 8.0
>
>iQA/AwUBPwdr92fqtj251CDhEQJZ2ACfSxH6N4JBiaHnMl8wIJxL+4 Whfy0AoIfT
>8wKHusl/p2M0a6HBdp01qcEb
>=g6N7
>-----END PGP SIGNATURE-----


Try to use double quote instead of single quote:
$_SERVER["HTTP_HOST"]


Jul 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
19811
by: koray | last post by:
hi everyone, in my form i have to take some date information in dd-mm-yy format. but i don't want user to use tabs while typing. for example s/he should simply type 280104 but 28/01/04 must...
6
2820
by: ALthePal | last post by:
Hi, I'm not sure if we are able to or even how to loop through the web forms in a VB.NET project during design time. In MSAccess we are able to go through the database -> forms collection and...
2
2104
by: Mark Hannon | last post by:
I am designing a PayPal shopping cart/store for a client and have placed several of PayPal's shopping cart forms on the page to correspond with different products. Each form has a unique name...
19
4065
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
0
3158
by: Andrew Dowding | last post by:
Hi Everybody, I have been looking at problems with my Windows Forms C# application and it's little Jet 4 (Access) database for the last few days. The Windows Forms app implements a facade and...
4
2666
by: Kathy | last post by:
I have a form to generate a report. On the form are several textboxes and a "Generate" button. I would like to have the button grayed (not enabled), unless the data in each of the dependant...
9
2087
by: Bob Alston | last post by:
I am looking for electronic forms software that would integrate well with MS Access. I have a client for whom I built a client database to replace and update one they had that was obsolete and...
19
247992
Atli
by: Atli | last post by:
Introduction At some point, all web developers will need to collect data from their users. In a dynamic web page, everything revolves around the users input, so knowing how to ask for and collect...
4
5867
by: dirk | last post by:
Hey, I'm new to php and I'm trying to write some php code so that I can insert data into a mysql database using html forms. I've got two text forms and a submit button. When entering data and...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3166
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
379
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.