PHP - Adding A Timestamp
How would I go about adding a timestamp to my image uploads so I don't erase image files with the same name? Also, what would be the correct use of the mysql_escape_string
<?php require_once('storescripts/connect.php'); mysql_select_db($database_phpimage,$phpimage); $uploadDir = 'upload/'; if(isset($_POST['upload' . $config])) { foreach ($_FILES as $file) { $fileName = $file['name']; $tmpName = $file['tmp_name']; $fileSize = $file['size']; $fileType = $file['type']; if($fileName==""){ $filePath = 'upload/'; } else{ $filePath = $uploadDir . $fileName; } $filePath = str_replace(" ", "_", $filePath); $result = move_uploaded_file($tmpName, $filePath); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } $fileinsert[]=$filePath; } } $mid = mysql_real_escape_string(trim($_POST['mid'])); $cat = mysql_real_escape_string(trim($_POST['cat'])); $item = mysql_real_escape_string(trim($_POST['item'])); $price = mysql_real_escape_string(trim($_POST['price'])); $about = mysql_real_escape_string(trim($_POST['about'])); $fields = array(); $values = array(); $updateVals = array(); for($i=1; $i<=4; $i++) { $fields[$i] = 'name'.$i; $values[$i] = mysql_real_escape_string(basename(trim($_FILES[$fields[$i]]['name']))); if($values[$i] != '') { $updateVals[] = "{$fields[$i]} = '{$values[$i]}'"; } } $updateNames = ''; if(count($updateVals)) { $updateNames = ", " . implode(', ', $updateVals); } $update = "INSERT INTO image (mid, cid, item, price, about, name1, name2, name3, name4) VALUES ('$mid', '$cat', '$item', '$price', '$about', '$values[1]', '$values[2]', '$values[3]', '$values[4]') ON DUPLICATE KEY UPDATE cid = '$cat', item = '$item', price = '$price', about = '$about' $updateNames"; $result = mysql_query($update) or die (mysql_error()); $id = mysql_insert_id(); ?> <p style="font-size:35px; font-family:Arial, Helvetica, sans-serif; color:#255E67; margin-left:25px;">Your Item Has Been Uploaded!</p> <script type="text/javascript"> setTimeout('ourRedirect()', 2000) function ourRedirect() { location.href='protator_php.php?mid=<?php echo $id ?>' } </script> Similar TutorialsHi People. Please can someone tell me the code to add a time stamp (date and time) to insert into the database at the time of filling out the form. At the moment my form is putting "null" into this database field. Code: [Select] <!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=iso-8859-1" /> <title>Stranded Flyer</title> </head> <body> <?php $host = 'localhost'; $usr = "the_user"; $password = 'thepassword'; $db_name = 'thedbname'; //connect to database mysql_connect ("$host","$usr","$password") or die ('Error During Connect:<br>'.mysql_error()); mysql_select_db ("$db_name") or die ('Error Selecting DB:<br>'.mysql_error()); $surname = mysql_real_escape_string($_POST['surname']); $firstname = mysql_real_escape_string($_POST['firstname']); $phone1 = mysql_real_escape_string($_POST['phone1']); $phone2 = mysql_real_escape_string($_POST['phone2']); $location = mysql_real_escape_string($_POST['location']); $qualifications = mysql_real_escape_string($_POST['qualifications']); $expertise = mysql_real_escape_string($_POST['expertise']); $assistance = mysql_real_escape_string($_POST['assistance']); $languages = mysql_real_escape_string($_POST['languages']); $e-mail = mysql_real_escape_string($_POST['e-mail']); $consent = mysql_real_escape_string($_POST['consent']); $published = mysql_real_escape_string($_POST['published']); $comments = mysql_real_escape_string($_POST['comments']); $other_info = mysql_real_escape_string($_POST['other_info']); $errorstring = ""; // default value of errorstring function makeSafe($value) { if (get_magic_quotes_gpc()) { $value = stripslashes($value); } $value = mysql_real_escape_string($value); return $value; } if(isset($_POST['submit'])) { // Validate all the code inputs // Captcha Validation require_once('recaptchalib.php'); $privatekey = "6Ld2xscSAAAAADwh3mCFkTObSHLAEKUAcU3ocpSv"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly $errorstring = $errorstring. "Invalid CAPTCHA, please try again"; } else { if ($surname =="") $errorstring = $errorstring. "Surname<br>"; if ($phone1 =="") $errorstring = $errorstring. "phone1<br>"; if ($phone2 =="") $errorstring = $errorstring. "phone2<br>"; if ($location =="") $errorstring = $errorstring. "location<br>"; if ($qualifications =="") $errorstring = $errorstring. "qualifications<br>"; if ($assistance =="") $errorstring = $errorstring. "assistance<br>"; if ($languages =="") $errorstring = $errorstring. "languages<br>"; if ($e-mail =="") $errorstring = $errorstring. "e-mail<br>"; if ($consent =="") $errorstring = $errorstring. "consent<br>"; if ($published =="") $errorstring = $errorstring. "published<br>"; if ($comments =="") $errorstring = $errorstring. "comments<br>"; if ($other_info =="") $errorstring = $errorstring. "other info<br>"; // does the errorstring = "nothing"? } // Figure out which error message to show i.e. field validation or CAPTCHA if ($errorstring !="") if (strstr($errorstring,"CAPTCHA")) echo $errorstring; else echo "You have not put anything in the following fields: <br><br> $errorstring"; //echo "If you have nothing to put in the box please type the word \"None\" or \"N\/A\""; //die ("Please try again, ensuring that you fill out all the fields!"); else { //echo "Your data has been saved"; $insert_query = "INSERT INTO HelperFormData (surname, firstname,phone1, phone2, location, qualifications, expertise, assistance, languages, e-mail, consent, published, comments, other_info,) VALUES ('$surname', '$firstname', '$phone1','$phone2', '$location', '$qualifications', '$expertise', '$assistance', '$languages', '$e-mail', '$consent', '$published', '$comments', '$other_info')"; $insert_action = mysql_query($insert_query) or die ('Error During Insert :<br>'.mysql_error().'<br><br>Error occured running the following code :<br>'.$insert_query); $id = mysql_insert_id(); echo "Thank you, Your details have been submitted."; //include "resultcard.php"; // Output what the form looks like // End of how the form looks } } if(!isset($_POST['submit']) || (isset($_POST['submit']) && !empty($errorstring))) { ?> <form name = "form1" method ="post" action=""> <table width="700" border="0" cellspacing="5" cellpadding="5" bgcolor = "#dddddd"> <caption> Submit Your Details </caption> <tr> <td width = "50"> </td> <td width = "240"> </td> <td width = "250"> </td> <td width = "160"><b>Example Input</b></td> </tr> <tr> <td> </td> <td>Surname</td> <td><input type='text' name='surname' size = '40' maxlength='30' value = '<?php echo $surname; ?>'></td> <td>Smith</td> </tr> <tr> <td> </td> <td>First Name</td> <td><input type='text' name='firstname' size = '40' maxlength='30' value = '<?php echo $firstname; ?>'></td> <td>Bill</td> </tr> <tr> <td> </td> <td>Phone 1</td> <td><input type='text' name='phone1' size = '40' maxlength='30' value = '<?php echo $phone1; ?>'></td> <td>07777 777777</td> </tr> <tr> <td> </td> <td>Phone 2</td> <td><input type='text' name='phone2' size = '40' maxlength= '30'value = '<?php echo $phone2; ?>'></td> <td>0118 123 4567</td> </tr> <tr> <td> </td> <td>Location</td> <td><input type='text' name='location' size = '40' maxlength='40'value = '<?php echo $location; ?>'></td> <td>52.289071,-1.952004</td> </tr> <tr> <td> </td> <td>Qualifications</td> <td><input type='text' name='qualifications' size = '40' maxlength='30' value = '<?php echo $qualifications; ?>'></td> <td>Electrician</td> </tr> <tr> <td> </td> <td>Expertise</td> <td><input type='text' name='qualifications' size = '40' maxlength='30' value = '<?php echo $expertise; ?>'></td> <td>Flexwings</td> </tr> <tr> <td> </td> <td>Assistance Offered</td> <td><input type='text' name='assistance' size = '40' maxlength='50' value = '<?php echo $assistance; ?>' /></td> <td>Trailer and Tow Car</td> </tr> <tr> <td> </td> <td>Language Skills</td> <td><input type='text' name='published' size = '40' maxlength='50' value = '<?php echo $language; ?>' /></td> <td><p>English / Spanish</p></td> </tr> <tr> <td> </td> <td>E-Mail</td> <td><input type='text' name='comments' size = '40' maxlength='50' value = '<?php echo $e-mail; ?>' /></td> <td><p>example@mail.net</p></td> </tr> <tr> <td> </td> <td>Consent</td> <td> <select name = "surface"> <option value = "Yes" <?php if ($_POST['consent'] == 'Yes') { echo 'selected="selected"'; } ?>>Yes</option> <option value = "No" <?php if ($_POST['consent'] == 'No') { echo 'selected="selected"'; } ?>>No</option> </select> </td> <td>Yes</td> </tr> <tr> <td> </td> <td>Published</td> <td> <select name = "food"> <option value = "Yes" <?php if ($_POST['published'] == 'Yes') { echo 'selected="selected"'; } ?>>Yes</option> <option value = "No" <?php if ($_POST['published'] == 'No') { echo 'selected="selected"'; } ?>>No</option> </select> </td> <td>Yes</td> </tr> <tr> <td> </td> <td>Comments</td> <td><textarea name= "remarks" input type = 'text' rows = "5" cols = "29" /><?php echo $remarks; ?></textarea></td> <td>As much info as possible 500 characters max</td> </tr> <tr> <td> </td> <td>Other Info</td> <td><textarea name= "warnings" input="input" type = 'text' rows = "5" cols = "29" /><?php echo $warnings; ?></textarea></td> <td>As much info as possible 500 characters max</td> </tr> <tr> <td> </td> <td><input type='submit' name='submit' value='Submit Your Info' /></td> <td colspan="2"> <? require_once('recaptchalib.php'); $publickey = "6Ld2xscSAAAAAH3_KiJoRLR4sEWFFQR4yAr5F1xi"; // you got this from the signup page echo recaptcha_get_html($publickey);?></td> </tr> </table> </form> </body> </html> <?php } ?> Using curl_multi, I have loaded up 3 url's and then printed the array. 1) How can I also set a timestamp on output to let me know when each url was run? 2) How can I explode the array to only display the data and timestamp, excluding the text "Array ( =>", "[1] =>", "[2] =>" and " )"? Code <?php function multiRequest($data, $options = array()) { // array of curl handles $curly = array(); // data to be returned $result = array(); // multi handle $mh = curl_multi_init(); // loop through $data and create curl handles // then add them to the multi-handle foreach ($data as $id => $d) { $curly[$id] = curl_init(); $url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d; curl_setopt($curly[$id], CURLOPT_URL, $url); curl_setopt($curly[$id], CURLOPT_HEADER, 0); curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1); // post? if (is_array($d)) { if (!empty($d['post'])) { curl_setopt($curly[$id], CURLOPT_POST, 1); curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']); } } // extra options? if (!empty($options)) { curl_setopt_array($curly[$id], $options); } curl_multi_add_handle($mh, $curly[$id]); } // execute the handles $running = null; do { curl_multi_exec($mh, $running); } while($running > 0); // get content and remove handles foreach($curly as $id => $c) { $result[$id] = curl_multi_getcontent($c); curl_multi_remove_handle($mh, $c); } // all done curl_multi_close($mh); return $result; } $data = array(array(),array()); $data[0]['url'] = 'http://search.yahooapis.com/VideoSearchService/V1/videoSearch?appid=YahooDemo&query=Pearl+Jam&output=json'; $data[1]['url'] = 'http://search.yahooapis.com/VideoSearchService/V1/videoSearch?appid=YahooDemo&query=Black+Eyed+Peas&output=json'; $data[2]['url'] = 'http://search.yahooapis.com/VideoSearchService/V1/videoSearch?appid=YahooDemo&query=Nirvana&output=json'; $r = multiRequest($data); print_r($r); ?> Output Array ( => Pearl Jam [1] => Black Eyed Peas [2] => Nirvana ) Preferred Output 01:00:01 Pearl Jam 01:00:02 Black Eyed Peas 01:00:03 Nirvana Hey there, Thanks for taking the time to read my thread. I've encountered a problem that I cannot figure out a way to solve. I need to calculate the remaining days until a specified unix timestamp. I haven't yet figured out how to get the amount of days until the timestamp. If anybody could tell me how to get the remaining days until a unix timestamp I would be grateful, thanks. Hi, I have in my DB a column with a timestamp as definition. Now I would like to have only the month and year of that column for further use in a form. How can I achieve that? Thanks! I have this date in database I must convert it to Unix Timestamp How ? 2010-11-11 09:04:44 I try this echo mktime($mydate); but its not work its return wrong Timestamp becase if I convert back it I have wrong date 2011-02-16 21:01:33 I have a update query that should be updating the timestamp when a "month" field is changed. I have the following code:
$month_update->bindParam(':timestamp', strtotime (date("Y-m-d H:i:s")), PDO::PARAM_INT);
The result that is returned is 1403198033. I need it to look like this 2014-03-26 07:09:06. I know I am missing something and I would greatly appreciate your help.
Thank you so much!
What is the proper way to turn a date that is in "m/d/Y" format, into a correct timestamp. When I try strtotime, then try to change it back to a date, it shows up incorrectly (defaulting to the 1969 date that it does when it messes up. I just need to be able to turn $date = '10/15/2011'; to and from a timestamp correctly. Any advice? $epocTime = $math.newInt($math.divide("$today.getTime()", "1000"))) How do i correctly update a timestamp? Code: [Select] $date = date("Y-m-d H:i:s"); mysql_query("UPDATE mmembers set time=now() where email=$myusername"); upon using PHP strtotime('2010-11-23 00:00:00') output a different values. Asia/Taipei int(1290441600) Europe/London int(1290470400) Expected : Same since I declare the date that need to convert as timestamp date_default_timezone_set('Asia/Taipei'); var_dump(strtotime('2010-11-23 00:00:00')); date_default_timezone_set('Europe/London'); var_dump(strtotime('2010-11-23 00:00:00')); Any explanation, Idea or alternative? Please help. Thanks I need some help. I have this script that pulls timestamps from the database. What I want to do is create a count of how many of those timestamps that were returned were from the morning(6am-12pm), Afternoon (12pm-6pm), Evening (6pm-12am), or Night (12am-6am). How do I do I parse the timestamps to do that and display the count. Thanks! Code: [Select] <?php /** * @author William Morris * @copyright 2010 */ include('inc/db.php'); //function to show date and time based on timestamp function showTIME($timestamp){ $date = date('F j Y h:i:s A', $timestamp); return $date; } $startdate = "2010-07-01"; $enddate = "2010-08-05"; //query to pull time stamps in between dates //convert dates into timestamp //$startdate = strtotime($_POST['startdate']); //$enddate = strtotime($_POST['enddate']); //convert dates into morning timestamp $startdate1 = strtotime($startdate."06:00:00"); $enddate1 = strtotime($enddate."11:59:59"); $sql = mysqli_query($conn, "SELECT event_time FROM event WHERE event = 'Registration' AND event_time BETWEEN '$startdate1' AND '$enddate1'"); while($row = mysqli_fetch_array($sql)){ echo showTIME($row['event_time'])."<br>"; } ?> Hello! I'm trying to develop some kind of RSS news aggregator and I want to show only feeds younger than 1day. I figured i could transform RSS pubDate to timestamp (strtotime()), but there are some feeds without timestamp (like: http://izklop.com/xmldata/rsslinks.xml). Is there any other way to do it, so I could find timestamp from those feeds without pubdate? If there isn't any other way, do You think it is ok, to just show last 5 feeds? I hope I made my self clear, and please forgive me for my English I'm using date_default_timezone_set("America/New_York"); to set the time, but the time isn't being displayed properly in mysql. The time is some other time zone. Do I have to set the time in mysql too? How do I do this? I have a column that is named date_created and has a value of DATETIME. How on this script can I insert only the time it was created. Is it NOW()) and if so how do I write it in the script? Code: [Select] // if residential if($_POST['type'] == ""){ mysql_select_db("", $con); $sql = "INSERT INTO apartments (username, title, county, town, type, description, phone, rooms, bath, square, rent, fees, service, imageurl1, imageurl2, imageurl3, imageurl4) VALUES ('".$myusername."', '".mysql_real_escape_string($_POST['title'])."', '".mysql_real_escape_string($_POST['county'])."', '".mysql_real_escape_string($_POST['town'])."', '".mysql_real_escape_string($_POST['type'])."', '".mysql_real_escape_string($_POST['description'])."', '".mysql_real_escape_string($_POST['phone'])."', '".$_POST[('rooms')]."', '".mysql_real_escape_string($_POST['bath'])."', '".mysql_real_escape_string($_POST['square'])."', '".mysql_real_escape_string($_POST['rent'])."', '".mysql_real_escape_string($_POST['fees'])."', '".mysql_real_escape_string($_POST['service'])."', '".mysql_real_escape_string($images[1])."', '".mysql_real_escape_string($images[2])."', '".mysql_real_escape_string($images[3])."', '".mysql_real_escape_string($images[4])."')"; $result = mysql_query($sql) or die(mysql_error()); I've been looking at converting my php timestamps to display as month, day, and the hour and minute the event occurred on, i tried; Code: [Select] $time = date("j/n H:i", $Events['timestamp']); But no success can anyone point me in the correct direction? Thanks im having problem comparing timestamps in my where clause for some strange reason...my query works perfect but when adding WHERE it doesn't bring up a result although it should...I've been playing about with it for almost a day now...and it doesn't make sense
unix_timestamp values start_date_time 1406411505 end_date_time 1407275505 now 1406461573my query SELECT i.item_id, i.title, i.price, @start_date_time := CONVERT_TZ(i.start_date_time, '+00:00', u.time_zone), @end_date_time := DATE_ADD(@start_date_time, INTERVAL 10 DAY), @end_date_time AS `end_date_time` FROM items i LEFT JOIN sub_categories sc ON sc.sub_category_id = i.sub_category_id LEFT JOIN categories c ON c.category_id = sc.category_id JOIN users u ON username = 'Destramic' WHERE UNIX_TIMESTAMP(@start_date_time) < UNIX_TIMESTAMP(NOW()) AND UNIX_TIMESTAMP(@end_date_time) >= UNIX_TIMESTAMP(NOW())if anyone can diagnose my problem I'd it would be much appreciated hey guys I wanting some information on the best way to store a timestamp and how I would convert that timestamp to another timezone please?
im guessing I would firstly store all timestamps to the database in GMT OR BST then convert after according to users timezone preference?
Is there a good website for this please on how this is possible...thank you
I have a timestamp field in my mySQL table and need to check if it's 14 day or older. What's the best way to do this? Any help will be appreciated Hi, I have a MySQL table with a timestamp field. I want this field to be automatically updated with the current date and time when a record is updated. How do I do that? This is my update query. Thanks: Code: [Select] $Sql="UPDATE MyTable SET client_alias='$client_alias',testimonial_date='$testimonial_date',order_ontime='$order_ontime',how_deal='$how_deal',order_condition='$order_condition',happy_colour='$happy_colour',colour_chosen='$colur_chosen',easy_use='$easy_use',effectiveness='$effectiveness',client_comments_eng='$client_comments_eng',client_comments_esp='$client_comments_esp',testimonial_updated_by='$testimonial_updated_by', _time_stamp='?????????' WHERE id_testimonial='$colname_testimonials_update_RS'"; mysql_query($Sql) or die('Error, query failed : ' . mysql_error()); any one know of any scripts to archive news items by timestamp? google searches just show tonnes of news archives.. not what i want! obviously using php, all news items have a timestamp, how would i go about this? very open ended question but ANY help would really be appreciated. Thanks! |