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 trialabdi ali
10,920 Pointsneed php debuger any one out there help!!
maybe i am getting syntax error it would be helpful if php was more like javascript where the console is showing u where u have got error everytime you make a mistake. but this php is just showing blank page really having difficult time any one who good php debugger out there please share
15 Answers
jamescool
44,592 PointsPlease look at your foreach loop. I might be wrong, but I think this should be run conditionally. Later in your code, you utilize the isset() function. I think you might need to wrap your foreach loop in an "if" statement that uses this function.
jamescool
44,592 Pointsalso maybe check all the paths to make sure the includes and require functions are linked to the proper paths.
jamescool
44,592 PointsYou can paste your PHP code here to validate it: http://phpcodechecker.com/
abdi ali
10,920 Pointsit saying no issue found and there is cleary a reason why i am not getting the result i want
jamescool
44,592 PointsWell, it's likely that there's another issue. Where are you running the PHP code?
abdi ali
10,920 Pointsmamp
jamescool
44,592 Pointsif you'd like, you can post your code and I can take a look at it. Of course, this might be hard if you're working with a very large application.
abdi ali
10,920 Points<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST["name"]);
$email = trim($_POST["email"]);
$message = trim($_POST["message"]);
if ($name == "" OR $email == "" OR $message == "") {
$error = "You must specify a value for name, email address, and message.";
}
foreach( $_POST as $value ){
if( stripos($value,'Content-Type:') !== FALSE ){
$error = "There was a problem with the information you entered.";
}
}
if ($_POST["address"] != "") {
$error = "Your form submission has an error.";
}
require_once("inc/phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
if (!$mail->ValidateAddress($email)){
$error = "You must specify a valid email address.";
exit;
}
if (!isset($error))
{
$email_body = "";
$email_body = $email_body . "Name: " . $name . "<br>";
$email_body = $email_body . "Email: " . $email . "<br>";
$email_body = $email_body . "Message: " . $message;
$mail->SetFrom($email, $name);
$address = "latiif607@gmail.com";
$mail->AddAddress($address, "abdi ali");
$mail->Subject = "Shirts 4 Mike Contact Form Submission | " . $name;
$mail->MsgHTML($email_body);
if($mail->Send()) {
header("Location: contact.php?status=thanks");
exit;
} else {
$error = "There was a problem sending the email " . $mail->ErrorInfo;
}
}
}
if (isset($error)) {
echo $error;
}
?><?php
$pageTitle = "Contact Mike";
$section = "contact";
include('inc/header.php'); ?>
<div class="section page">
<div class="wrapper">
<h1>Contact</h1>
<?php if (isset($_GET["status"]) AND $_GET["status"] == "thanks") { ?>
<p>Thanks for the email! I’ll be in touch shortly!</p>
<?php } else { ?>
<?php if (isset($error)) {echo $error; } ?>
<p>I’d love to hear from you! Complete the form to send me an email.</p>
<form method="post" action="contact.php">
<table>
<tr>
<th>
<label for="name">Name</label>
</th>
<td>
<input type="text" name="name" id="name">
</td>
</tr>
<tr>
<th>
<label for="email">Email</label>
</th>
<td>
<input type="text" name="email" id="email">
</td>
</tr>
<tr>
<th>
<label for="message">Message</label>
</th>
<td>
<textarea name="message" id="message"></textarea>
</td>
</tr>
<tr style="display: none;">
<th>
<label for="address">Address</label>
</th>
<td>
<input type="text" name="address" id="address">
<p>Humans (and frogs): please leave this field blank.</p>
</td>
</tr>
</table>
<input type="submit" value="Send" name="submit">
</form>
<?php } ?>
</div>
</div>
<?php include('inc/footer.php') ?>
jamescool
44,592 Pointsand you also explain precisely what the issue is? (is the page displaying but not functioning somehow, or are you simply getting a blank page?)
abdi ali
10,920 Pointsis not large application is just one of the course here in php i want if an error exist i show which can of error exist if not i send email n redirect the user to thank you page. if i fill the form with the correct name email the redirection works just good but if i don't type anything it show blank page rather than displaying the error
abdi ali
10,920 Pointsthe foreach loop just prevents malicious people attacking my code nothing else i don't thinks that is the issue though
abdi ali
10,920 Pointsohhh ok got your point now thank you
abdi ali
10,920 Pointssolved
jamescool
44,592 PointsGood! I'm glad you got it.
Alena Holligan
Treehouse TeacherAdd the following two line to the top of you file to display errors with your code
error_reporting(E_ALL);
ini_set('display_errors',1);
For more information, check out the docs here http://php.net/manual/en/function.error-reporting.php
Also the "PHP Standards and Best Practices" is a great course :)