NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page [resolved] PhP question

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

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 01-06-2007, 09:04 PM THREAD STARTER               #1 (permalink)
NamePros Regular
Join Date: Jul 2005
Location: U.S.A.
Posts: 655
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">
????: NamePros.com http://www.namepros.com/programming/277978-resolved-php-question.html
<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.
????: NamePros.com http://www.namepros.com/showthread.php?t=277978
-CP
Coolprogram is offline  
Old 01-07-2007, 02:20 AM   #2 (permalink)
NamePros Regular
 
beaver6813's Avatar
Join Date: May 2005
Location: England
Posts: 392
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:
<?
????: NamePros.com http://www.namepros.com/showthread.php?t=277978
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 is offline  
Old 01-07-2007, 05:51 AM   #3 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,568
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
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.
????: NamePros.com http://www.namepros.com/showthread.php?t=277978

PHP Code:
if(strlen($_POST['uname']) > && strlen($_POST['pwd1']) > && strlen($_POST['pwd2']) > && strlen($_POST['email']) > && strlen($_POST['dob']) > && strlen($_POST['G']) > 0)
????: NamePros.com http://www.namepros.com/showthread.php?t=277978
{
    
// continue with submission...
}
else
{
    
// They missed a field
    
echo 'You missed a field.';

Matthew. is offline  
Old 01-07-2007, 11:13 AM   #4 (permalink)
NamePros Regular
 
beaver6813's Avatar
Join Date: May 2005
Location: England
Posts: 392
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
beaver6813 is offline  
Old 01-07-2007, 11:18 AM   #5 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,568
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
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
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.
????: NamePros.com http://www.namepros.com/showthread.php?t=277978

Matt
Matthew. is offline  
Old 01-07-2007, 11:30 AM   #6 (permalink)
NamePros Regular
 
beaver6813's Avatar
Join Date: May 2005
Location: England
Posts: 392
beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough
 




Originally Posted by Matthew.
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
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.
????: NamePros.com http://www.namepros.com/showthread.php?t=277978

Matt
This conversation tells the user otherwise Ill mark this as resolved now
beaver6813 is offline  
Closed Thread


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


Liquid Web Smart Servers  
All times are GMT -7. The time now is 10:53 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger