Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKonrad Pilch
2,435 PointsWrong
Is theres someting wrong with this code? It doesnt re-direct me nor show errors , while i know the errors are written goon in the index.
<?php
session_start();
require 'functions.php';
if(isset($_POST['sign-up'])) {
if(isset($_POST['first_name'])) {
$first_name = mysqli_real_escape_string(trim($_POST['first_name']));
if(strlen($first_name) > 2) {
//passed
if(strlen($first_name) < 26) {
//passed
} else {
$_SESSION['status']['register']['error'][] = 'The First Name is too long!';
} else {
$_SESSION['status']['register']['error'] = 'The First Name is less than 3 characters!';
} else {
$_SESSION['status']['register']['error'][] = 'The First Name is blank!.';
}
if(isset($_POST['last_name'])) {
$last_name = mysqli_real_escape_string(trim($_POST['last_name']));
} if(strlen($last_name) > 2) {
//passed
if(strlen($last_name) < 26) {
//passed
} else {
$_SESSION['status']['register']['error'][] = 'The Last name is too long!';
} else {
$_SESSION['status']['register']['error'] = 'The Last name is less than 3 characters!';
} else {
$_SESSION['status']['register']['error'][] = 'The Last name is blank!.';
}
if(isset($_POST['email_address'])) {
$email_address = mysqli_real_escape_string(trim($_POST['email_address']));
} if(strlen($email_address) > 10) {
//passed
if(strlen($email_address) < 161) {
//passed
} else {
$_SESSION['status']['register']['error'][] = 'The First Name is too long!';
}else {
$_SESSION['status']['register']['error'] = 'The First Name is less than 3 characters!';
} else {
$_SESSION['status']['register']['error'][] = 'The First Name is blank!.';
}
if(isset($_POST['username'])) {
$username = mysqli_real_escape_string(trim($_POST['username']));
} if(strlen($username) > 3) {
//passed
if(strlen($username) < 31) {
//passed
} else {
$_SESSION['status']['register']['error'][] = 'The First Name is too long!';
}else {
$_SESSION['status']['register']['error'] = 'The First Name is less than 3 characters!';
} else {
$_SESSION['status']['register']['error'][] = 'The First Name is blank!.';
}
if(isset($_POST['password'])) {
$password = mysqli_real_escape_string(trim($_POST['password']));
} if(strlen($password) > 8) {
//passed
} else {
$_SESSION['status']['register']['error'][] = 'The First Name is too long!';
}else {
$_SESSION['status']['register']['error'] = 'The First Name is less than 3 characters!';
} else {
$_SESSION['status']['register']['error'][] = 'The First Name is blank!.';
}
if(isset($_POST['tos'])) {
// Checked
$tos = mysqli_real_escape_string(trim($_POST['tos']));
} else{
$_SESSION['status']['register']['error'][] = 'The First Name is blank!.';
}
header('Location: index.php');
}else {
header('Location: index.php');
}
Konrad Pilch
2,435 PointsSO i managed to see thath theres something wrong with : this code :
//passed
} else {
$_SESSION['status']['register']['error'][] = 'The First Name is too long!';
} else {
$_SESSION['status']['register']['error'][] = 'The First Name is too long!';
} else {
$_SESSION['status']['register']['error'][] = 'The First Name is too long!';
}
My current code is :
if(isset($_POST['first_name'])) {
$first_name = $_POST['first_name'];
if(strlen($first_name) > 2) {
//passed
} else {
$_SESSION['status']['register']['error'][] = 'The First Name is too long!';
} else {
$_SESSION['status']['register']['error'][] = 'The First Name is too long!';
} else {
$_SESSION['status']['register']['error'][] = 'The First Name is too long!';
}
}
}
miguelcastro2
Courses Plus Student 6,573 PointsA logfile is a file that PHP errors are stored. PHP will show you errors on the page, but sometimes when a PHP error occurs, the error will not be able to print to the web page you are working on and it will give you a blank page. A blank page will not explain what the problem is. The logfile will show you the error that is causing the page not to work and will help you solve the issue. Logfiles are important to use when working on developing web applications.
What server are you using? WAMP/XAMP?
Konrad Pilch
2,435 PointsIm using MAMP.
miguelcastro2
Courses Plus Student 6,573 Points2 Answers
miguelcastro2
Courses Plus Student 6,573 PointsCheck your log files.
Mat Sanders
4,819 PointsTo answer part of your question on the redirect. Make sure none of your code puts out any info to the user, including whitespaces, This will stop header from working. Common issue is the inculdes. Remove any ?> at the end of your include files, stops rogue whitespaces popping up. Also some browsers won't see the URI in the header unless it's a full url. IE www.example.com/index.php
Konrad Pilch
2,435 PointsKonrad Pilch
2,435 PointsI dont get you both: /
Log files? what is that? login file? if you meant thath im just doing the registration system now.
Mat, whatdo you mean about none of your code putsout any info to the user , including whitespace?