1inaMinion Posted October 21, 2016 Share Posted October 21, 2016 I am new to this. So far, all I've learned for PHP covered mostly the contact form (My notes: http://www.carrotsails.com/notes/phpMaster.html) I created a nice contact form here: http://carrotsails.com/Resume/php/contactForm.php All is great to this point and I'm so proud of myself for making it this far. Then, I make my website portfolio, and as soon as I upload it, everything changes. There is part of my php sitting at the top where it doesn't belong. It appears the $results are displaying above my webpage and they aren't supposed to even show unless prompted and furthermore, not there. Although there are some other details with the website I also need to address, if the trouble I'm seeing here is php related, I need some help with it. Here is the website for your viewing: http://carrotsails.com/ Here is the code below. Thank you for your help. <?php if ($_POST["submit"]) { if (!$_POST['name']) { $error="</br>Please enter your name"; } if (!$_POST['email']) { $error.="</br>Please enter your email address"; } if (!$_POST['comment']) { $error.="</br>Please enter a comment"; } if ($_POST['email']!="" AND !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { $error.="</br>Please enter a valid email address"; } if ($error) { $result='<div class="alert alert-danger"><strong>There were error(s) in your form:</strong> ' .$error.'</div>'; } else { if (mail("carrotsails@yahoo.com", "Comment from carrotsails.com!", "Name: ".$_POST['name']." Email: ".$_POST['email']." Comment: ".$_POST['comment'])) { $result='<div class="alert alert-success"><strong>Thank you I\'ll be in touch.</strong></div>'; } else { $result='<div class="alert alert-danger"><strong>Sorry, there was an error sending your message. Please try again later.</strong></div>'; } } } ?> <!doctype html> <html lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <title>Erika's Test Portfolio</title> <link rel="stylesheet" type="text/css" media="all" href="css/global01.css"> <link rel="stylesheet" type="text/css" media="all" href="http://fonts.googleapis.com/css?family=ABeeZee"> <!-- LIGHTBOX GALLERY STYLES --> <link rel="stylesheet" type="text/css" href="css/lightboxGalleryStyles.css"> <!-- MY STYLES --> <link rel="stylesheet" type="text/css" href="css/CarrotStyles.css"> <style type="text/css"> </style> </head> <body> <div id="about"> <div id="home"><div><!-- Deleted content for simplicity --></div></div> <div id="MeetErika"> <h2>Meet Erika</h2> <!-- Deleted content for simplicity --> </div> <div id="MyPortfolio"> <h2>The Portfolio</h2> <!-- Deleted content for simplicity --> </div> <div id="Contact"> <h2>Contact Erika</h2> <p>Please get in touch - I'll get back to you as soon as I can.</p> <?php echo $result; ?> <form method="post"> <div class="form-group"> <label for="name">Your Name:</label> <input type="text" name="name" class="form-control" placeholder="Your Name" value="<?php echo $_POST['name']; ?>"/> </div> <div class="form-group"> <label for="email">Your Email:</label> <input type="email" name="email" class="form-control" placeholder="Your Email" value="<?php echo $_POST['email']; ?>"/> </div> <div class="form-group"> <label for="comment">Your Comments:</label> <textarea class="form-control" name="comment" placeholder="Your Comments"><?php echo $_POST['comment']; ?></textarea> </div> <input type="submit" name="submit" class="btn" value="Submit" /> </form> </div> </div> <div id="mainpage"> <nav> <div><img src="images/ErikaFlowerLogo01.png" class="flower"/></div> <h1>Erika's Portfolio</h1> <ul id="navigation"> <li><a href="#home">Home</a></li> <li><a href="#MeetErika">Meet Erika</a></li> <li><a href="#MyPortfolio">Portfolio</a></li> <li><a href="#Contact">Contact</a></li> </ul> </nav> <div id="content"></div> </div> <!-- LIGHTBOX JAVASCRIPT LINK --> <script type="text/javascript" src="js/lightboxGalleryJs.js"></script> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/302378-newbie-php-problem/ Share on other sites More sharing options...
NotionCommotion Posted October 21, 2016 Share Posted October 21, 2016 Hi 1inaminion, First of all, good job putting your PHP logic one place (You put it at the top of the page which is fine, just don't mix it in your HTML) and your html template another. There are template systems such as smarty which take this a little bit further, but I recommend you keep doing what you are doing for a while, and then look into templates. You should be proud of yourself! Do you have a decent understanding of HTML/CSS? If so, PHP is not magic. It just spits out some HTML to the browser (and sometimes other things, but let's not worry about that for now). Just look at the HTML. Is it what you expected and wanted? If not, then your PHP script needs to be tweaked. Good luck and have fun! Quote Link to comment https://forums.phpfreaks.com/topic/302378-newbie-php-problem/#findComment-1538474 Share on other sites More sharing options...
requinix Posted October 22, 2016 Share Posted October 22, 2016 Is this resolved? What you're describing sounds like PHP isn't installed or running on the server, but when I look at the contact form everything appears to be in order. Quote Link to comment https://forums.phpfreaks.com/topic/302378-newbie-php-problem/#findComment-1538487 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.