Page 1 of 1

PHP Form With No Results

Posted: Tue Apr 29, 2008 8:18 pm
by latoyale
My code is producing completely no results, the code just resets itself and does not add info to the database. Please help!

Code: Select all

<?php
 
session_start(); 
include("database.php");
include("signup.php");
 
$username = $_POST['username'];
$password = $_POST['password'];
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$password2 = $_POST['password2'];
$street = $_POST['street'];
$apt = $_POST['apt'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$birthday_month = $_POST['birthday_month'];
$birthday_day = $_POST['birthday_day'];
$birthday_year = $_POST['birthday_year'];
$gender = $_POST['gender'];
$question = $_POST['question'];
$answer = $_POST['answer'];
$answer1 = $_POST['answer1'];
 
$conn = mysql_connect("ip", "db", "password") or die(mysql_error());
mysql_select_db('db', $conn) or die(mysql_error());
 
if(isset($username) && isset($password) && isset($password1) && ($answer) && ($answer1)){
    if(strlen($password) < 6 || strlen($username) > 64){
    echo "Password is either too short or too long\n";
    }else {
        if($password != $password1){
    echo "Password do not match\n";
   }else {
        if($answer != $answer1){
        echo "Password do not match\n";
    }else {
        $sql = "SELECT * FORM 'users' WHERE 'username' = '$username'";
        $res = mysql_query($sql) or die(mysql_error());
        if(mysql_num_rows($res)){
        echo"this username already exists";
    }else {
        $sql ="INSERT INTO 'users' (username, password,firstname, lastname, email,  password2, street, apt, city, state, zip, phone, birthday_month, birthday_day, birthday_year, gender, question, answer, answer1) VALUES ('$username','$password','$firstname','$lastname','$email','$password2','$street','$apt','$city','$state','$zip','$phone','$birthday_month','$birthday_day', '$birthday_year','$gender','$question','$answer','$answer1')";
    $res = mysql_query($sql) or die(mysql_error());
    echo "Your Information has been successfully added to the database.";
    
   }
}
}
} 
}
 
?>
 
 
 
 
 

Re: PHP Form With No Results

Posted: Wed Apr 30, 2008 4:15 am
by aceconcepts
I would imagine it has something to do with your conditional statements.

Try setting error variables for each instance:

Code: Select all

 
$errorVar=0;
 
if($password != $password1)
{
   $erroVar=1;
   $passwordErr=1;
}
 
if($answer != $answer1)
{
   $errorVar=1;
   $answerErr=1;
}
 
if($errorVar==0)
{
   //add to database etc...
}
   else
{
   //output specific error
}
 
$errorVar is a general error variable used to determine whether any errors have occurred.

Each error has it's own specific error indication i.e. $answerErr=1 indicates that the answers do not match.

I think this approach would be a more structured and logical one.

Hope it helps.