Page 1 of 1

Code Produces Blank Results - Syntax Error

Posted: Wed Apr 30, 2008 10:03 am
by latoyale
Good Morning,

My form is producing a blank screen with no results. I think its a syntax error. Can anyone please point me in the right direction?

** Thank you all you have helped me thus far.

Code: Select all

<?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'];
 
 
$connect = mysql_connect('ip', 'db', 'password) or die("Unable to Connect to Database<br>".mysql_error());
mysql_select_db('db) or die(mysql_error());
 
 
if(isset($username) && isset($password) && isset($password2) && ($answer) && ($answer1))
{
 
if($password != $password2){
    echo "Password do not match\n";
}
if(strlen($password) < 6 || strlen($password) > 64){
    echo "Password is either too short or too long\n";
}
if($answer != $answer1){
    echo "Answers do not match\n";
}
 
else{
   mysql_query("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')") or die(mysql_error()); 
 
echo "Your Information has been successfully added to the database. Thank you for your registration";
}
}
 
                    
mysql_close($connect) or die("Unable to Close Database<br>".mysql_error());
 
 
?>
 

Re: Code Produces Blank Results - Syntax Error

Posted: Wed Apr 30, 2008 10:20 am
by Mightywayne
'password)

You didn't put an apostrophe there. Unfortunately I don't think it'll help you any, but here's to hoping.

Also, learn to use periods. If you don't, you look like an idiot coder. And the first password error should say "passwords".

Re: Code Produces Blank Results - Syntax Error

Posted: Wed Apr 30, 2008 11:06 am
by latoyale
Thank you. I made the changes but I still don't have any results. Is there any error in my if else syntax ? Is there a code I can put in to check where the break in my code is? Apparently the code is dying somewhere but I can't figure out where..

Re: Code Produces Blank Results - Syntax Error

Posted: Wed Apr 30, 2008 11:08 am
by nickvd
make sure that error reporting is turned on...

error_reporting(E_ALL);

Re: Code Produces Blank Results - Syntax Error

Posted: Wed Apr 30, 2008 11:17 am
by latoyale
Unfortunately I am still getting nothing but a blank page. To test your error code, I purposely put in the wrong password and it gave me detailed info on the error. That code is awesome! However when I put in my correct database info, I get nothing.

This is really a mystery.

Re: Code Produces Blank Results - Syntax Error

Posted: Wed Apr 30, 2008 11:22 am
by onion2k
If "if(isset($username) && isset($password) && isset($password2) && ($answer) && ($answer1)) {" is false then you will get a blank page...

Re: Code Produces Blank Results - Syntax Error

Posted: Wed Apr 30, 2008 11:26 am
by latoyale
Hmm, interesting...

I got the syntax of that piece of code from a tutorial.

What does it mean?

I thought it means if you are error checking variable username, password, password2, answer and answer1 then do the following...

What should I have there instead if I want to check all those variables?

Re: Code Produces Blank Results - Syntax Error

Posted: Wed Apr 30, 2008 11:30 am
by onion2k
It's the last two that I think your problem lies with ... "&& ($answer) && ($answer1)". They will only be true if they contain a value that isn't "" (an empty string) and isn't "0" (zero). If either of them does contain that then you'll get a blank page.

Re: Code Produces Blank Results - Syntax Error

Posted: Wed Apr 30, 2008 11:49 am
by latoyale
You are ABSOLUTELY right!! :)

I put in this code

else
{
echo "If statement proved FALSE\n";
}

and it proved false. I am going to add javascript validation to the form to make sure users fill out those fields.

Thank you all so much!!

Re: Code Produces Blank Results - Syntax Error

Posted: Thu May 01, 2008 3:07 am
by onion2k
latoyale wrote:I am going to add javascript validation to the form to make sure users fill out those fields.
If the user has Javascript turned off then that won't solve the problem. You really need to validate everything in PHP.

Re: Code Produces Blank Results - Syntax Error

Posted: Fri May 02, 2008 1:22 pm
by RobertGonzalez
If you don't mind me asking, what tutorial did you use? That is just horrible teaching.