forms - Inserting drop down value into MySQL table -
i have site, people supposed able arrange meetings users within system. i'm having difficulties getting start , endtime form appear in mysql database, i'm using timestamp format saving values. me figuring out i'm going wrong?
<?php $page_title = "create event"; //check if form has been submitted if (isset($_post['submitted'])) { $errors = array(); //initialize error array // check event name if (empty($_post['event_name'])) { $errors[] = 'you have not given event name.'; } else { $en = trim($_post['event_name']); } // check event location if (empty($_post['location'])) { $errors[] = 'you have not determined meeting taking place.'; } else { $l = trim($_post['location']); } if (empty($_post['starttime'])) { $errors[] = 'you have not determined when meeting starting.'; } else { $s = trim($_post['starttime']); } if (empty($_post['endtime'])) { $errors[] = 'you have not determined when meeting ending.'; } else { $e = trim($_post['endtime']); } if (empty($errors)) { // if ok // create event in database // require_once ('../mysqli_connect.php'); // db connect // make query $host="mysql.itu.dk"; $username="tklo"; $password="cave57waits49"; $db_name="project_cluster"; $tbl_name="events"; mysql_connect("$host", "$username", "$password") or die ("cannot connect"); mysql_select_db("$db_name") or die ("cannot select database"); $sql="insert $tbl_name (event_name, location, starttime, endtime)values('$en', '$l', '$s', '$e')"; $result=mysql_query($sql); if($result){ echo "succesfull"; echo "<br>"; echo "<a href='newevent.php'>back main page</a>"; } else { echo "error"; } mysql_close(); } else { echo '<h2>error!</h2> <p class="error">the following error(s) occured:<br />'; foreach ($errors $msg) { // print each error echo " - $msg<br />\n"; } } } ?> <form action="newevent.php" method="post"> <p>name event: <input type="text" name="event_name" value="<?php if(isset($_post['event_name'])) echo $_post['event_name']; ?>" /></p> <p>where meeting taking place: <input type="text" name="location" value="<?php if(isset($_post['location'])) echo $_post['location']; ?>" /></p> <p>beginning of event <input type="text" name="starttime" value="<?php if(isset($_post['starttime'])) echo $_post['starttime']; ?>" /></p> <p>end of event <input type="text" name="endtime" value="<?php if(isset($_post['endtime'])) echo $_post['endtime']; ?>" /></p> <input type="submit" value="go" /> <input type="hidden" name="submitted" value="true" /> </form>
Comments
Post a Comment