Code Produces Blank Results - Syntax Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
latoyale
Forum Commoner
Posts: 25
Joined: Fri Apr 04, 2008 1:16 am

Code Produces Blank Results - Syntax Error

Post 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());
 
 
?>
 
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Re: Code Produces Blank Results - Syntax Error

Post 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".
latoyale
Forum Commoner
Posts: 25
Joined: Fri Apr 04, 2008 1:16 am

Re: Code Produces Blank Results - Syntax Error

Post 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..
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Re: Code Produces Blank Results - Syntax Error

Post by nickvd »

make sure that error reporting is turned on...

error_reporting(E_ALL);
latoyale
Forum Commoner
Posts: 25
Joined: Fri Apr 04, 2008 1:16 am

Re: Code Produces Blank Results - Syntax Error

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Code Produces Blank Results - Syntax Error

Post by onion2k »

If "if(isset($username) && isset($password) && isset($password2) && ($answer) && ($answer1)) {" is false then you will get a blank page...
latoyale
Forum Commoner
Posts: 25
Joined: Fri Apr 04, 2008 1:16 am

Re: Code Produces Blank Results - Syntax Error

Post 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?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Code Produces Blank Results - Syntax Error

Post 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.
latoyale
Forum Commoner
Posts: 25
Joined: Fri Apr 04, 2008 1:16 am

Re: Code Produces Blank Results - Syntax Error

Post 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!!
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Code Produces Blank Results - Syntax Error

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Code Produces Blank Results - Syntax Error

Post by RobertGonzalez »

If you don't mind me asking, what tutorial did you use? That is just horrible teaching.
Post Reply