[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 01-06-2007, 08:04 PM   #1 (permalink)
NamePros Regular
 
Join Date: Jul 2005
Location: U.S.A.
Posts: 655
0.00 NP$ (Donate)

Coolprogram has a spectacular aura aboutCoolprogram has a spectacular aura about


PhP question

Hey guys,
I have a question, that is probably sooo simple, yet I cannot figure it out. Here's my question, why won't this code work
PHP Code:
<?php
session_start
();
require(
"dbconn.php");
?>
<html>
<center>
<body bgcolor="black">
<div align="center"><font color="#ffffff"><font size="5">Registration</font></font></div>
<div align="center"><font color="#ffffff"><font size="5">&nbsp;</div>
<form action="member.php" method="POST">
Username:
<input type="text" name="uname" value="Username Here">
<br>
Password:
<input type="password" name="pwd1" value="password">
<br>
Password Again:
<input type="password" name="pwd2" value="password2">
<br>
E-Mail:
<input type="text" name="email" value=""> (ex. info@genera3d.com)
<br>
Date Of Birth(optional):
<input type="text" name="dob" value="">
<br>
Gender(optional):
<input type="text" name="G" value="">
<br>
<input type="submit" name="sub" value="SUBMIT!">
<?php
if($login == 'register');
$uname = $_POST['uname'];
$pwd1 = $_POST['pwd1'];
$pwd2 = $_POST['pwd2'];
$email = $_POST['email'];
if(!
$uname || !$pwd1);
echo (
'Please fill out the form');
exit;
?>
Thanks,
-CP

I knew it was going to be simple, I figured it out, my bad to anyone that has/had tried to help me, I put require, instead of include LOL
-CP

Hey guys, since I figured out that problem, guess what? I have another. I need to make it so that way if they do not fill out all of the fields, it says something like error: all fields not complete.
-CP
Coolprogram is offline  
Old 01-07-2007, 01:20 AM   #2 (permalink)
NamePros Regular
 
beaver6813's Avatar
 
Join Date: May 2005
Location: England
Posts: 349
65.50 NP$ (Donate)

beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough


Quote:
Hey guys, since I figured out that problem, guess what? I have another. I need to make it so that way if they do not fill out all of the fields, it says something like error: all fields not complete.
-CP
PHP Code:
<?
if(empty($_POST['uname']) || empty($_POST['pwd1']) || empty($_POST['pwd2']) || empty($_POST['email']) || empty($_POST['dob']) || empty($_POST['G'])) {
echo
"You Forgot A Field!";
} else {
//Proceed with the rest of the code here
}
?>
Rep or $NP Appreciated
__________________
-Beaver6813.com V5 Soon!
beaver6813 is offline  
Old 01-07-2007, 04:51 AM   #3 (permalink)
Stud Sausage
 
Join Date: Dec 2006
Location: England
Posts: 1,546
34.41 NP$ (Donate)

Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of

Adoption Breast Cancer Breast Cancer Cancer Survivorship
Quote:
Originally Posted by beaver6813
PHP Code:
<?
if(empty($_POST['uname']) || empty($_POST['pwd1']) || empty($_POST['pwd2']) || empty($_POST['email']) || empty($_POST['dob']) || empty($_POST['G'])) {
echo
"You Forgot A Field!";
} else {
//Proceed with the rest of the code here
}
?>
Rep or $NP Appreciated
You should not use empty() to validate fields as it will return false if "0" is entered, considering in some cases 0 is a valid input it's best not to use it.

The best way is to check the string length using strlen.

PHP Code:
if(strlen($_POST['uname']) > 0 && strlen($_POST['pwd1']) > 0 && strlen($_POST['pwd2']) > 0 && strlen($_POST['email']) > 0 && strlen($_POST['dob']) > 0 && strlen($_POST['G']) > 0)
{
    
// continue with submission...
}
else
{
    
// They missed a field
    
echo 'You missed a field.';
}
__________________
My NamePros Tools
(firefox plugin, google gadget etc)
Matthew. is offline  
Old 01-07-2007, 10:13 AM   #4 (permalink)
NamePros Regular
 
beaver6813's Avatar
 
Join Date: May 2005
Location: England
Posts: 349
65.50 NP$ (Donate)

beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough


None of the field values should be 0 anyway. Unless someones first name, last name, date of birth, gender or whatever is 0. And the password should definately not be 0. So in a way it checks that as well :P
__________________
-Beaver6813.com V5 Soon!
beaver6813 is offline  
Old 01-07-2007, 10:18 AM   #5 (permalink)
Stud Sausage
 
Join Date: Dec 2006
Location: England
Posts: 1,546
34.41 NP$ (Donate)

Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of

Adoption Breast Cancer Breast Cancer Cancer Survivorship
Quote:
Originally Posted by beaver6813
None of the field values should be 0 anyway. Unless someones first name, last name, date of birth, gender or whatever is 0. And the password should definately not be 0. So in a way it checks that as well :P
lol, true however to me it's always best not to show a code like you did as an example or answer to a question as someone will come along, read what they think it does and use it on a field that may be 0.

Matt
__________________
My NamePros Tools
(firefox plugin, google gadget etc)
Matthew. is offline  
Old 01-07-2007, 10:30 AM   #6 (permalink)
NamePros Regular
 
beaver6813's Avatar
 
Join Date: May 2005
Location: England
Posts: 349
65.50 NP$ (Donate)

beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough


Quote:
Originally Posted by Matthew.
Quote:
Originally Posted by beaver6813
None of the field values should be 0 anyway. Unless someones first name, last name, date of birth, gender or whatever is 0. And the password should definately not be 0. So in a way it checks that as well :P
lol, true however to me it's always best not to show a code like you did as an example or answer to a question as someone will come along, read what they think it does and use it on a field that may be 0.

Matt
This conversation tells the user otherwise Ill mark this as resolved now
__________________
-Beaver6813.com V5 Soon!
beaver6813 is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 01:40 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85