I have no experience with php and feel that I am doing something wrong with the file I have created. I am building a (HTML) web form page that will submit the data to csv file. I plan to use a php function to retrieve the csv file data and insert it into an HTML table.
I thought I was doing everything correctly until I started adding a select drop-down option box and two text areas in the HTML form, then I started getting errors in the php file. I would greatly appreciate someone looking at my code and providing me some direction on what I am doing wrong. I have listed the php file code below and the separate HTML file code below that separately. Thank you so much for any help you can give me.
I thought I was doing everything correctly until I started adding a select drop-down option box and two text areas in the HTML form, then I started getting errors in the php file. I would greatly appreciate someone looking at my code and providing me some direction on what I am doing wrong. I have listed the php file code below and the separate HTML file code below that separately. Thank you so much for any help you can give me.
<?php if($_POST['formSubmit'] == "Submit") { $errorMessage = ""; if(empty($_POST['submittedBy'])) { $errorMessage .= "<li>You forgot to enter your name!</li>"; } if(empty($_POST['myEmail'])) { $errorMessage .= "<li>You forgot to enter your email address!</li>"; } if(empty($_POST['serves'])) { $errorMessage .= "<li>You forgot to enter how many people the dish will serve!</li>"; } if(empty($_POST['time'])) { $errorMessage .= "<li>You forgot to enter how much time it will take!</li>"; } $varName = $_POST['submittedBy']; $varEmail = $_POST['myEmail']; $varServes = $_POST['serves']; $varTime = $_POST['time']; $varCourse = $_POST['course'] $varIngredients = $_POST['ingredients'] $varPreparation = $_POST['preparation'] if(!empty($errorMessage)) { $fs = fopen("myrecipes.csv","a"); fwrite($fs,$varName . ", " . $varEmail . ", " . $varServes . ", " . $varTime . ", " . $varCourse . ", " . $varIngredients . ", " . $varPreparation . "\n"); fclose($fs); header("Location: thankyou.html"); exit; } } ?> <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Recipe Form</title> </head> <body> <?php if(!empty($errorMessage)) { echo("<p>There was an error with your form:</p>\n"); echo("<ul>" . $errorMessage . "</ul>\n"); } ?> <form action="myrecipe.php" method="post"> <input type="text" name="submittedBy" value="<?=$varName;?>" /> <input type="text" name="myEmail" value="<?=$varEmail;?>" /> <input type="text" name="serves" value="<?=$varServes;?>" /> <input type="text" name="time" value="<?=$varTime;?>" /> <select name="course" value="<?=$varCourse;?> > </select> <textarea name="ingredients" value="<?=$varIngredients;?> > </textarea> <textarea name="preparation" value="<?=$varPreparation;?> > </textarea> <input type="submit" name="formSubmit" value="Submit" /> </form> </body> </html>
<!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Recipe Form</title> <style type="text/css"> #popitmenu{ position: absolute; background-color: white; border:1px solid black; font: normal 12px Georgia; line-height: 18px; z-index: 100; visibility: hidden; } #popitmenu a{ text-decoration: none; padding-left: 6px; color: #990000; display: block; } #popitmenu a:hover{ /*hover background color*/ background-color: #ffffcc; } </style> <script type="text/javascript"> /*********************************************** * Pop-it menu- © Dynamic Drive (www.dynamicdrive.com) * This notice MUST stay intact for legal use * Visit http://www.dynamicdrive.com/ for full source code ***********************************************/ var defaultMenuWidth="100px" //set default menu width. var linkset=new Array() //SPECIFY MENU SETS AND THEIR LINKS. FOLLOW SYNTAX LAID OUT linkset[0]='<a href="recipe_form.html">Recipes</a>' linkset[0]='<a href="family_recipes.html">Family Recipes</a>' //linkset[0]+='<hr>' //Optional Separator ////No need to edit beyond here var ie5=document.all && !window.opera var ns6=document.getElementById if (ie5||ns6) document.write('<div id="popitmenu" onmouseover="clearhidemenu();" onmouseout="dynamichide(event)"></div>') function iecompattest(){ return (document.compatMode && document.compatMode.indexOf("CSS")!=-1)? document.documentElement : document.body } function showmenu(e, which, optWidth){ if (!document.all&&!document.getElementById) return clearhidemenu() menuobj=ie5? document.all.popitmenu : document.getElementById("popitmenu") menuobj.innerHTML=which menuobj.style.width=(typeof optWidth!="undefined")? optWidth : defaultMenuWidth menuobj.contentwidth=menuobj.offsetWidth menuobj.contentheight=menuobj.offsetHeight eventX=ie5? event.clientX : e.clientX eventY=ie5? event.clientY : e.clientY //Find out how close the mouse is to the corner of the window var rightedge=ie5? iecompattest().clientWidth-eventX : window.innerWidth-eventX var bottomedge=ie5? iecompattest().clientHeight-eventY : window.innerHeight-eventY //if the horizontal distance isn't enough to accomodate the width of the context menu if (rightedge<menuobj.contentwidth) //move the horizontal position of the menu to the left by it's width menuobj.style.left=ie5? iecompattest().scrollLeft+eventX-menuobj.contentwidth+"px" : window.pageXOffset+eventX-menuobj.contentwidth+"px" else //position the horizontal position of the menu where the mouse was clicked menuobj.style.left=ie5? iecompattest().scrollLeft+eventX+"px" : window.pageXOffset+eventX+"px" //same concept with the vertical position if (bottomedge<menuobj.contentheight) menuobj.style.top=ie5? iecompattest().scrollTop+eventY-menuobj.contentheight+"px" : window.pageYOffset+eventY-menuobj.contentheight+"px" else menuobj.style.top=ie5? iecompattest().scrollTop+event.clientY+"px" : window.pageYOffset+eventY+"px" menuobj.style.visibility="visible" return false } function contains_ns6(a, B)/> { //Determines if 1 element in contained in another- by Brainjar.com while (b.parentNode) if ((b = b.parentNode) == a) return true; return false; } function hidemenu(){ if (window.menuobj) menuobj.style.visibility="hidden" } function dynamichide(e){ if (ie5&&!menuobj.contains(e.toElement)) hidemenu() else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget)) hidemenu() } function delayhidemenu(){ delayhide=setTimeout("hidemenu()",500) } function clearhidemenu(){ if (window.delayhide) clearTimeout(delayhide) } if (ie5||ns6) document.onclick=hidemenu </script> <link href="familysite.css" rel="stylesheet"> </head> <body> <div id="wrapper"> <h1 id="header"><img src="Images/Family_Logo_Name_web.gif" height="159" width="446" alt="Billings Family Logo"></h1> <div class="nav"> <ul> <li><a href="index.html">Home</a></li> <li><a href="calendar.html">Calendar</a></li> <li><a href="pictures.html">Pictures</a></li> <li><a href="recipe_form.html" onmouseover="showmenu(event,linkset[0], '125px')" onmouseout="delayhidemenu()">Recipes</a></li> <li><a href="familyblog.html">Family Blog</a></li> <li><a href="designs.html">Billings Designs</a></li> </ul> </div><br> <div id="content"><br> <p>Let's accumulate a family recipe book! Please complete the following form to share a recipe:</p> <form method="post" action="myrecipe.php"> <label for="submittedBy">Submitted By:</label> <input type="text" name="submittedBy" id="submittedBy"> <label for="myEmail">Email:</label> <input type="text" name="myEmail" id="myEmail"> <label for="serves"># of Servings:</label> <input type="text" name="serves" id="serves"> <label for="time">Total Time:</label> <input type="text" name="time" id="time"> <select size="1" name="course" id="course"> <option>Please select the course for the dish:</option> <option value="mainDish">Main Dish</option> <option value="sideDish">Side Dish</option> <option value="dessert">Dessert</option> <option value="salad">Salad</option> <option value="bread">Bread</option> <option value="beverage">Beverage</option> </select><br /> <br /> <textarea name="ingredients" id="ingredients" cols="60" rows="10">Please enter ingredients here</textarea> <br /> <textarea name="preparation" id="preparation" cols="60" rows="10">Please enter preparation instructions here</textarea> <input type="submit" value="Submit Recipe"> </form> </div> <br> <div id="footer"> Copyright © 2013<br> <a href="mailto:roxannebillings@gmail.com">roxannebillings@gmail.com</a></div> </div> </body> </html>