jp612 Posted December 29, 2010 Report Share Posted December 29, 2010 Im just going through a form proccessing & emailing tutorial for PHP and it doesnt seem to be doing anything so far. my index.php file: <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> <?php if($_GET['page'] == "design") { echo "Website Design Services"; }else if($_GET['page'] == "graphic") { echo "Graphic Design Services"; }else if($_GET['page'] == "contact") { echo "Contact Us"; }else if($_GET['page'] == "about") { echo "About Us"; }else{ echo "Debes Web Design Services"; } ?> </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="css/style.css" rel="stylesheet" type="text/css" /> <?php $include_home = "include(\"includes/home.php\")"; if($include_home) echo "<link href=\"css/home.css\" rel=\"stylesheet\" type=\"text/css\" />"; ?> <!--[if lt IE 8]> <link rel="stylesheet" type="text/css" href="css/ie7.css" /> <![endif]--> </head> <body> <div id="page-wrapper"> <div id="header-wrapper"> <div id="header"> <div id="logo"> <a href="index.php?page=home"><img src="images/debes-logo.png" width="210" height="88" alt="Debes Web Design Logo"/></a> </div> <div id="navbar"> <ul> <li> <a href='index.php?page=home'>Home</a> </li> <li> <a href='index.php?page=design'>Web Design</a> </li> <li> <a href='index.php?page=graphic'>Graphic Design</a> </li> <li> <a href='index.php?page=contact'>Contact</a> </li> <!-- <li> <a href='index.php?page=about'>About</a> </li> --> </ul> </div> </div> </div> <?php if($_GET['page'] == "design") { include("includes/design.html"); }else if($_GET['page'] == "graphic") { include("includes/graphic.html"); }else if($_GET['page'] == "contact") { include("includes/contact.php"); }else if($_GET['page'] == "about") { include("includes/about.html"); }else{ include("includes/home.php"); } ?> <div id="footer"> <div id="footer-content"> <p>© debesdesign.com 2010</p> </div> </div> </div> </body> </html> my contact.php include: <?php if(isset($_SESSION['name'])){ echo $_SESSION['name']; } ?> <div id="content-wrapper"> <div id="content-background"> <div id="content"> <div id="content-left-pane-design"> <h2>Contact Us</h2> <p>Got an enquiry? Feel free to contact us about pricing, your website, etc.</p> <div id="form-contact"> <form action="form_contact.php" method="post"> <div id="input-name"><span id="name">Name*</span> <input type="text" value="<?php if(isset($_SESSION['name'])){ echo $_SESSION['name']; } ?>" name="name" /> <?php if(isset($_SESSION['error_name'])){ echo $_SESSION['error_name']; } ?> <br /></div> <div id="input-company"> <span id="company">Company</span> <input type="text" value="" name="company" /> <br /></div> <div id="input-website"> <span id="website">Website</span> <input type="text" value="" name="website"/> <br /></div> <div id="input-email"> <span id="email">Email*</span> <input type="text" value="<?php if(isset($_SESSION['email'])){ echo $_SESSION['email']; } ?>" name="email"/> <?php if(isset($_SESSION['error_email'])){ echo $_SESSION['error_email']; } ?> <br /></div> <div id="input-enquiry"><span id="enquiry">Enquiry*</span> <textarea rows="10" cols="60" name="enquiry"><?php if(isset($_SESSION['enquiry'])){ echo $_SESSION['enquiry']; } ?></textarea> <?php if(isset($_SESSION['error_enquiry'])){ echo $_SESSION['error_enquiry']; } ?> <br /></div> <div id="input-submit"><input type="submit" value="Send" name="submit" /></div> </form> </div> </div> <div id="content-right-pane-design"> <div id="right-pane"> </div> </div> </div> </div> <div id="maincontentborder-bottom"></div> </div> and finally my form_contact.php which proccesses the form: <?php session_start(); $num = 0; if($_POST['submit']) { if(strlen($_POST['name']) > 0) { $num = $num; $_SESSION['name'] = $_POST['name']; unset($_SESSION['error_name']); }else{ $num = $num + 1; $_SESSION['error_name'] = "You have not filled out your name!"; } if(strlen($_POST['email']) > 0) { $num = $num; $_SESSION['email'] = $_POST['email']; unset($_SESSION['error_email']); }else{ $num = $num + 1; $_SESSION['error_email'] = "You have not filled out your email address!"; } if(strlen($_POST['enquiry']) > 0) { $num = $num; $_SESSION['enquiry'] = $_POST['enquiry']; unset($_SESSION['error_enquiry']); }else{ $num = $num + 1; $_SESSION['error_enquiry'] = "You have not given us a message!"; } if($num == 0) { // process form echo "success"; }else{ echo "error2!"; header("location: includes/contact.php"); }else{ echo "error!"; } ?> Whats supposed to happen so far is that if i dont enter any text into the enquiry, email and name forms i should be taken back to my contact.php file with error messages echo'd saying that i didnt fill in anything, but all i get is a blank page. If i fill in all the data i get a blank page to no message saying success. I guess its just a code error somewhere but i have looked all through. I put the session_start(); at the top of my index.php above the doctype where it belongs since my selected page is always included using. Im not too sure what the problem is but it looks ok. I put all the session stuff into the contact.php into and next to the forms so it can show error messages and proccess the data. thanks. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted December 29, 2010 Report Share Posted December 29, 2010 Usually the header() function throws an error if anything is sent to the browser before the header() function is used. My impression is that the line echo "error2!"; Would cause an error (which you may not see if you have PHP errors turned off. I would suggest removing that line and testing again. If that still doesn't work, let me know, and I'll look at it more in-depth. Also, don't you need to be redirecting to "index.php?page=contact"? For future reference, it is helpful to do development work with PHP errors turned on, so you can see any error messages. You can either do that by adding ini_set('display_errors', '1'); error_reporting(E_ALL); to your code, or editing your PHP.ini file (search online for tutorials - it's pretty easy.) Quote Link to comment Share on other sites More sharing options...
jp612 Posted December 29, 2010 Author Report Share Posted December 29, 2010 Ah yes! I turned on php errors, removed the error2 echo and put in the correct url in the header (dunno what i was thinking there). Turns out i had a small syntax error just before the header function so it never took me back to my contact page. I forgot to put a } on the end of my first header function: if($num == 0) { // process form echo "success"; }else{ header("location: index.php?page=contact"); }else{ header("location: index.php?page=contact"); } So I fixed that and it works now. Thanks a lot! I thought that php always shows info about the error no matter what. Knowing I have to turn it on will save me a lot of headache in the future. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted December 29, 2010 Report Share Posted December 29, 2010 I thought that php always shows info about the error no matter what. That depends on the server. I believe that applications like MAMP/WAMP have errors off by default, so you have to either include the code to turn errors on, or change your php.ini file. Most web hosts keep PHP errors off. Keep in mind that while turning PHP errors on during development is useful, it's usually a good idea to hide errors on a live website, in case an error message exposes information that might be used maliciously. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.