Dynadot

[Resolved] PhP question

Spaceship Spaceship
Watch
Impact
7
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:
<?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"> </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. [email protected])
<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
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
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:
<?
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 :)
 
0
•••
beaver6813 said:
PHP:
<?
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:
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.';
}
 
0
•••
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
 
0
•••
beaver6813 said:
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. :tu:

Matt
 
0
•••
Matthew. said:
beaver6813 said:
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. :tu:

Matt
:) This conversation tells the user otherwise ;) Ill mark this as resolved now :)
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back