Jump to content

mannyson

Members
  • Posts

    20
  • Joined

  • Last visited

mannyson's Achievements

Member

Member (2/5)

0

Reputation

1

Community Answers

  1. I did try that exactly. It gives me the alert error " alert("Invalid date. Example: 30 Tuesday 2013 15:50:00"); ". It's in the above function. Even before it gave me this error when ever I tried to use an html input value variable for the newdate.
  2. You're code is kind of confusing. Can you insert it into the full code I have, along with the "$('.new-date').val()"?
  3. I found this js countdown code. It works except for one little problem. var newdate = $('.new-date').val(); $(".countdown").countdown({ date: "2 October 2015 03:00:00", format: "on" }); I would like to know how can I pass my "newdate" variable to the "date"? So instead of "2 October 2015 03:00:00"", I want to have "newdate". How do I input it inside that? Here is the full code. <script> (function (e) { e.fn.countdown = function (t, n) { function i() { eventDate = Date.parse(r.date) / 1e3; currentDate = Math.floor(e.now() / 1e3); if (eventDate <= currentDate) { n.call(this); clearInterval(interval) } seconds = eventDate - currentDate; days = Math.floor(seconds / 86400); seconds -= days * 60 * 60 * 24; hours = Math.floor(seconds / 3600); seconds -= hours * 60 * 60; minutes = Math.floor(seconds / 60); seconds -= minutes * 60; days == 1 ? thisEl.find(".timeRefDays").text("day") : thisEl.find(".timeRefDays").text("days"); hours == 1 ? thisEl.find(".timeRefHours").text("hour") : thisEl.find(".timeRefHours").text("hours"); minutes == 1 ? thisEl.find(".timeRefMinutes").text("minute") : thisEl.find(".timeRefMinutes").text("minutes"); seconds == 1 ? thisEl.find(".timeRefSeconds").text("second") : thisEl.find(".timeRefSeconds").text("seconds"); if (r["format"] == "on") { days = String(days).length >= 2 ? days : "0" + days; hours = String(hours).length >= 2 ? hours : "0" + hours; minutes = String(minutes).length >= 2 ? minutes : "0" + minutes; seconds = String(seconds).length >= 2 ? seconds : "0" + seconds } if (!isNaN(eventDate)) { thisEl.find(".days").text(days); thisEl.find(".hours").text(hours); thisEl.find(".minutes").text(minutes); thisEl.find(".seconds").text(seconds) } else { alert("Invalid date. Example: 30 Tuesday 2013 15:50:00"); clearInterval(interval) } } var thisEl = e(this); var r = { date: null, format: null }; t && e.extend(r, t); i(); interval = setInterval(i, 1e3) } })(jQuery); $(document).ready(function () { function e() { var e = new Date; e.setDate(e.getDate() + 60); dd = e.getDate(); mm = e.getMonth() + 1; y = e.getFullYear(); futureFormattedDate = mm + "/" + dd + "/" + y; return futureFormattedDate } var newdate = $('.new-date').val(); $(".countdown").countdown({ date: "2 October 2015 03:00:00", format: "on" }); }); </script>
  4. Yes that does seem to work. Now the only issue I have is the "f (is_uploaded_file($_FILES['files']['tmp_name'][$key]))". Despite having a file selected, it will return the "else(file is empty)" error. It won't process beyond that. Now if I remove that check, it'll process. But then it'll go to the next error "You have uploaded a forbidden extension!" on submit, even if a file is not selected. I think the check "if (!empty($_FILES['files'])) " is not really doing it's job.
  5. Yes I can do that and I have done it. But that's not the solution I am looking for it. I am inserting 1 record with option to choose multiple images. The record will insert if I have it outside the loop. And the images will insert if I have selected them. The issue is that if the selected image(s) gives an error, the record itself will insert anyways I just want to make sure that if errors are produced by the selected images, that to not insert the record data into the table. That's all.
  6. Can you provide an example with the array? It would really help. Thanks.
  7. Here's the deal. I am getting into uploading multiple images with a record details. Image file paths are stored in "images" table and records are stored in "records" table. They both work fine separately. I am just having issue using both of them together since "foreach loop" is involved. I want to make sure the image is uploaded and check for errors before inserting the image and record details. Since this for uploading "multiple files", all this checking for errors is inside "foreach loop". It will insert the images fine, but it will also insert the record details multiple times(depending on the images attached) in the records table. If I insert the record details outside the loop, it'll insert only once but then it'll insert the data with or without the images attached. Here's a basic set up of what I am talking about . I removed the extra code. I just would like to know where I can place the insert into records code relative to the foreach loop so that It checks the errors for file uploads and inserts details in to the database after that. if(isset($_POST['submit']) { $record_name = trim($_POST['record_name']); $record_details = trim($_POST['record_details']); $record_type = trim($_POST['record_type']); $date = date('Y-m-d H:i:s'); if(empty($record_name)) { echo 'record name is required!'; } else if(empty($record_details)) { $error = 'record details are required!'; } else if(empty($record_type)) { $error = 'Type is required!'; } else { if(isset($_FILES['files'])){ $userdir = $_SERVER['DOCUMENT_ROOT'] .'/comp/images/'; if(!is_dir($userdir)){ mkdir($userdir, 0775, true); } foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){ if(is_uploaded_file($_FILES['files']['tmp_name'][$key])) { if(in_array($type, $allowed)) { try { $insert_image = $db->prepare("INSERT INTO images(record_id, image_path, date) VALUES(:record_id, :image_path, :date)"); $insert_image->bindParam(':record_id', $record_id); $insert_image->bindParam(':image_path', $image_path); $insert_image->bindParam(':date', $date_added); $result_image = $insert_image->execute(); if($result_image == false) { echo 'There was a problem!'; } else { move_uploaded_file($temp, $file_path); echo 'Your image has been saved.'; } $insert_record = $db->prepare("INSERT INTO records(record_name, record_type, record_details, date) VALUES(:record_name, :record_type, :record_details, :date)"); $insert_record->bindParam(':record_name', $record_name); $insert_record->bindParam(':record_type', $record_type); $insert_record->bindParam(':record_details', $record_details ); $insert_record->bindParam(':date', $date); $result_record = $insert_record->execute(); if($result_record == true) { echo 'Your record has been saved.'; } else { $error = 'record not added!'; } } catch(Exception $e) { $error = die($e->getMessage()); } } else { echo 'You have uploaded a forbidden extension!'; } } else { echo 'File is empty!'; } } } } }
  8. I am curious to know what the best practice is for something like this. I as a user post a record. In that record is an option for me to upload images. Since I am storing my record in "records" table, is it a good idea to ALSO store the record images(file paths) in the same table? Or would it make more sense to store the images is a separate table called "images"?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.