View Full Version : Else statement keeps firing - simple registration form

03-15-2007, 11:04 PM
Im pretty new to php have many to wade through a bun of syntax errors and code what is pretty much a completed registration form but its not quite there.

The Plan:
when the page loads the php checks to see if all the values are needed to register are there if not it creates a form to input the data. When the user hits submit the php runs again sees the datas there then sends to database.

The Problem:
The form is not displaying the php keeps creating blank records in to the table.

<?php $self = $_SERVER['PHP_SELF'];
$UserName = $_POST['UserName'];
$Password = $_POST['Password'];
$Email = $_POST['Email'];

if( ( !UserName ) or ( !Password) or ( !Email) )


$form ="To register fill in the details below and hit submit!";
$form.="<form action=\"$self\" ";
$form.=" method=\"post\"> Username: ";

$form.="<input type=\"text\" name=\"UserName\"";
$form.=" value=\"$UserName\"> <br>Password: ";

$form.="<input type=\"text\" name=\"Password\"";
$form.=" value=\"$Password\"> <br>Email: ";

$form.="<input type=\"text\" name=\"Email\"";
$form.=" value=\"$Password\"> <br>";

$form.="<input type=\"submit\" value=\"Submit\">";
echo( $form );
{ $conn = @mysql_connect( "localhost", "root", "")
or die ("could not connect to mysql"); #Connect to mysql
$db = @mysql_select_db( "thewu", $conn )
or die ("Could not select database"); #select database

$sql = "insert into logins
(UserName,Password,Email) values
(\"$UserName\",\"$Password\",\"Email\") "; #Create Query
$result= @mysql_query($sql, $conn )
or die("Couldnt run query mate"); #Run query
if( $result ) {echo( "New user $UserName added"); }

Heres the code theres no error messages from php it seems to me too keep firing the else statement no matter what. Any help would be great

03-15-2007, 11:08 PM
Sure you don't get any errors? No $ infront of the variables.
Should also try this

if((empty($UserName)) or (empty($Password)) or (empty($Email) )

03-16-2007, 12:03 AM
Hey Thanks alot
changing to your if statmenet everything worked perfect :thumbsup: