will35010 Posted November 5, 2008 Share Posted November 5, 2008 This php code adds a record using the php, but when I open the page it displays php errors on the bottom and adds an empty record before it gets the post data. I added the if (isset($_POST to try to fix it but it still does it. Can you guys please help me? Thanks, Also how do I use code tags to put my code inside of it like other post? Code: <!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>Panola Playhouse -- Add Event</title> <link rel="stylesheet" type="text/css" href="view.css" media="all"> <script type="text/javascript" src="view.js"></script> <script type="text/javascript" src="calendar.js"></script> </head> <body id="main_body" > <img id="top" src="top.png" alt=""> <div id="form_container"> <h1><a>Add Event</a></h1> <form id="form_101367" class="appnitro" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <div class="form_description"> <h2>Add Event</h2> <p></p> </div> <ul > <li id="li_1" > <label class="description" for="element_1">Event Date </label> <span> <input id="element_1_1" name="month" class="element text" size="2" maxlength="2" value="" type="text"> / <label for="element_1_1">MM</label> </span> <span> <input id="element_1_2" name="day" class="element text" size="2" maxlength="2" value="" type="text"> / <label for="element_1_2">DD</label> </span> <span> <input id="element_1_3" name="year" class="element text" size="4" maxlength="4" value="" type="text"> <label for="element_1_3">YYYY</label> </span> <span id="calendar_1"> <img id="cal_img_1" class="datepicker" src="calendar.gif" alt="Pick a date."> </span> <script type="text/javascript"> Calendar.setup({ inputField : "element_1_3", baseField : "element_1", displayArea : "calendar_1", button : "cal_img_1", ifFormat : "%B %e, %Y", onSelect : selectDate }); </script> </li> <li id="li_2" > <label class="description" for="element_2">Event Time </label> <span> <input id="element_2_1" name="hour" class="element text " size="2" type="text" maxlength="2" value=""/> : <label>HH</label> </span> <span> <input id="element_2_2" name="minute" class="element text " size="2" type="text" maxlength="2" value=""/> : <label>MM</label> </span> <span> <select class="element select" style="width:4em" id="element_2_4" name="ampm"> <option value="AM" >AM</option> <option value="PM" >PM</option> </select> <label>AM/PM</label> </span> </li> <li id="li_3" > <label class="description" for="element_3">Event Name </label> <div> <input id="element_3" name="name" class="element text medium" type="text" maxlength="255" value=""/> </div> </li> <li id="li_4" > <label class="description" for="element_4">Event Description </label> <div> <textarea id="element_4" name="description" class="element textarea medium"></textarea> </div> </li> <li class="buttons"> <input type="hidden" name="form_id" value="101367" /> <input id="saveForm" class="button_text" type="submit" name="submit" value="Add Event" /> </li> </ul> </form> <div id="footer"> Software by Will Morris & Daniel Cerveny</a> </div> </div> <img id="bottom" src="bottom.png" alt=""> </body> </html> <?php //PHP script to add events to database //This will give us very good details on errors error_reporting(E_ALL); //Connect to database require '../include/opendb.php'; require '../include/config.php'; //this keeps php from displaying errors on page load if (isset($_POST['month'])) { //Date Varible Assignment $month = $_POST['month']; $day = $_POST['day']; $year = $_POST['year']; //Time Varible Assignment $hour = $_POST['hour']; $min = $_POST['minute']; $ampm = $_POST['ampm']; //Event Name & Description Varible Assignment $name = $_POST['name']; $desc = $_POST['description']; //Generate a uniqueID //$eventID = $db->nextID('playhouse'); //Send the Form Data to the Database $query = "INSERT INTO events (eventmonth, eventday, eventyear, hour, minute, ampm, eventname, eventdescription) VALUES ('$month', '$day', '$year', '$hour', '$min', '$ampm', '$name', '$desc')"; mysqli_query($conn, $query) or die('Error: ' . mysql_error()); //Print what was entered echo "This Data Was Added To Events."; echo "$month $day $year $hour $min $ampm $name $desc"; } mysql_close($conn); ?> <a href="./admin_index.html">Go Back to Admin Page</a> Edit(thorpe): Added tags. Link to comment https://forums.phpfreaks.com/topic/131434-solved-form-working-but-adding-extra-record/ Share on other sites More sharing options...
will35010 Posted November 5, 2008 Author Share Posted November 5, 2008 Thank you!!! Link to comment https://forums.phpfreaks.com/topic/131434-solved-form-working-but-adding-extra-record/#findComment-682602 Share on other sites More sharing options...
will35010 Posted November 5, 2008 Author Share Posted November 5, 2008 anybody??? I think its something wrong with my isset Link to comment https://forums.phpfreaks.com/topic/131434-solved-form-working-but-adding-extra-record/#findComment-682605 Share on other sites More sharing options...
l0ve2hat3 Posted November 5, 2008 Share Posted November 5, 2008 try if (!empty($_POST['month'])) Link to comment https://forums.phpfreaks.com/topic/131434-solved-form-working-but-adding-extra-record/#findComment-682610 Share on other sites More sharing options...
will35010 Posted November 5, 2008 Author Share Posted November 5, 2008 I'm a moron. It did work. I just saved it wrong so it didn't have it in it when I ftp'd over. I'm sorry for the bad post. Thanks for the reply though. I'll have to remember that one. Link to comment https://forums.phpfreaks.com/topic/131434-solved-form-working-but-adding-extra-record/#findComment-682615 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.