PHP - Date From Url To Database
heres the problem
i have 3 things in url bar $day $month $year (its important it stays 3 variables in url) i know how to get them but what i need is convert these 3 into 1 value and store it to DATE(it would be good to be date type for later use) type in mysql any ideas? Similar TutorialsHi, Currently I am making a module for joomla. every article has an publish date, if the article was published in 7 days ago, it will displayed as "article in last week", My idea is to use today's date - publish date, if the result is greater than 7 and smaller than 14, the article will be displayed as "article in last week. Any one know how to write this code? Here is what I have got, but not working. <?php $todays_date = date("Y-m-d"); $result = mysql_query("select * from jos_content where $test between $todays_date-14 and $todays_date-7"); while($row = mysql_fetch_array($result)) { echo "$todays_date - $row[title]"; } ?> Hi fellas, this is really kicking my arse and i know its so simple! I retrieve a date from the database, done! I am manipulating it to display as i want, done! How the hell do i add 365 days to this date? $date= ($row['date']); $subscription = strtotime($date); echo "<p>Subscription renewal date: ". date('l jS F Y', $subscription) . "</p>"; Hi I have started my error checking for my form. I am understand that the date must be inserted in the format yyyy/mm/dd but on my form i need it to be inserted in the format dd/mm/yyyy. I have wrote some code but have only been doing php about a week properly so I can't see what my error is. Whenever I try to insert the date, the form its self does not error but if i check the database the date is simply 0000/00/00. Can anyone help? if(isset($_POST['submit'])) { $first_name = mysql_real_escape_string($_POST['first_name']); $last_name = mysql_real_escape_string($_POST['last_name']); $DOB = mysql_real_escape_string($_POST['DOB']); $sex = mysql_real_escape_string($_POST['sex']); $email = mysql_real_escape_string($_POST['email']); $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $agree = mysql_real_escape_string($_POST['agreed']); $creation_date = mysql_real_escape_string($_POST['creation_date']); $user_type = mysql_real_escape_string($_POST['member_type']); $access_level = mysql_real_escape_string($_POST['access_level']); $validation = mysql_real_escape_string($_POST['validation_id']); $club_user = mysql_real_escape_string($_POST['user_type']); $date_check = "/^([0-9]{2})/([0-9]{2})/([0-9]{4})$/"; if($first_name == "") { $message = "Please enter a first name"; $success = 0; } else if($last_name == "") { $message = "Please enter a surname"; $success = 0; } else if($DOB =="") { $message = "Please enter your date of birth."; $success = 0; } else if(!(preg_match("/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/", $DOB))) { $message = "Please enter your birthday in the format dd/mm/yyyy"; $success = 0; } else if($email =="") { $message = "Please enter a correct email."; $success = 0; } else if($username =="") { $message = "Please enter a username."; $success = 0; } else if($password =="") { $message = "Please enter a password greater than 6 characters long."; $success = 0; } else { $DOB = $explode[2]."-".$explode[1]."-".$explode[0]; $password_md5 = md5($password); $insert_member= "INSERT INTO Members (`first_name`,`last_name`,`DOB`,`sex`,`email`,`username`,`password`,`agree`,`creation_date`,`usertype`,`access_level`,`validationID`) VALUES ('".$first_name."','".$last_name."','".$DOB."','".$sex."','".$email."','".$username."','".$password_md5."','".$agree."','".$creation_date."','".$user_type."','".$access_level."', '".$validation."')"; $insert_member_now= mysql_query($insert_member) or die(mysql_error()); $url = "thankyou.php?name=".$_POST['username']; header('Location: '.$url); I am trying to update last logged in entry in the database upon succesful login. I may be way off in the logic here or I may be missing something simple. I don't get any errors and it logs in fine. Just does not update the lastvisit field in the database. Code: [Select] //record date of most recent login $result = mysql_query("SELECT username FROM users WHERE user_id ='".$_SESSION['userId'] . "'"); $dtCreated = date('Y-m-d'); mysql_query("UPDATE users SET lastvisit=('$dtCreated') WHERE username = $result"); hello there.. i have a problem with my php coding where i want to keep date choose by user in the database. this is the drop down date Code: [Select] <select name="Date_Day"> <option> - Day - </option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> <select name="Date_Month"> <option> - Month - </option> <option value="01">January</option> <option value="02">Febuary</option> <option value="03">March</option> <option value="04">April</option> <option value="05">May</option> <option value="06">June</option> <option value="07">July</option> <option value="08">August</option> <option value="09">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <select name="Date_Year"> <option> - Year - </option> <option value="2010">2010</option> <option value="2011">2011</option> <option value="2012">2012</option> <option value="2013">2013</option> <option value="2014">2014</option> <option value="2015">2015</option> <option value="2016">2016</option> <option value="2017">2017</option> <option value="2018">2018</option> <option value="2019">2019</option> <option value="2020">2020</option> <option value="2021">2021</option> <option value="2022">2022</option> <option value="2023">2023</option> <option value="2024">2024</option> <option value="2025">2025</option> <option value="2026">2026</option> </select> the code to connect to the database Code: [Select] $date_year= ($_POST['Date_Year']); $date_month=($_POST['Date_Month']); $date_day=($_POST['Date_Day']); $date=$date_year."-".$date_month."-".$date_day; $query="INSERT INTO aduan (date) VALUES ('date($date)')"; $result=mysql_query($query); if($result){ echo 'Registration success.'; ?><script>window.location ='thanks.php'</script> <?php } else echo 'Registration failed';} when enter a value of date, the database will just show '0000-00-00'.. really hope for your help.. I can't figure out how to select something from the database that is under today's date. This is what I have: if($row['date'] == ".date('Y-m-d').' 00:00:00'."' AND date < '".date('Y-m-d').' 23:59:59'.") Any help would be greatly appreciated. I have my database set to insert the current time stamp when an entry is made into the table, I am then trying to retrieve via the following code: $select_view_idea="SELECT * FROM $tbl_name5 WHERE message_number='$message_number'"; $result_view_idea=mysql_query($select_view_idea); while($row_view_idea=mysql_fetch_assoc($result_view_idea)){ extract($row_view_idea); } date_default_timezone_set('US/Eastern'); $date=date('l, F jS Y h:i:s A T', $date); echo $date; The above is outputting: Wednesday, December 31st 1969 07:33:31 PM EST the database contains: 2011-11-18 00:47:56 Hi people I have some code to retireve dates from a database, see below. The issue is i can not find a way to change the output to d,m,Y instead of what the data comes back from database. Any help with this would be much appriciated. The transaction date is getting the invoice date created back as 2020-04-01 etc, but how to swap this code?, I dont think i can do it within the array. $statement_transactions = array(); $client_total_balance = $client_opening_balance; foreach ($client_invoices as $invoice_entry) { $transaction = [ 'transaction_type' => self::TRANSACTION_TYPE_INVOICE, 'transaction_date' => $invoice_entry->invoice_date_created, 'transaction_amount' => $invoice_entry->invoice_total, 'invoice_id' => $invoice_entry->invoice_id, 'client_id' => $invoice_entry->client_id, 'user_company' => $invoice_entry->user_company, 'invoice_amount_id' => $invoice_entry->invoice_amount_id, 'invoice_item_subtotal' => $invoice_entry->invoice_item_subtotal, 'invoice_item_tax_total' => $invoice_entry->invoice_item_tax_total, 'invoice_total' => $invoice_entry->invoice_total, 'invoice_sign' => $invoice_entry->invoice_sign, 'invoice_status_id' => $invoice_entry->invoice_status_id, 'invoice_date_created' => $invoice_entry->invoice_date_created, 'invoice_time_created' => $invoice_entry->invoice_time_created, 'invoice_number' => $invoice_entry->invoice_number, ]; $client_total_balance += $invoice_entry->invoice_total; $statement_transactions[] = $transaction; }
I need to add date of birth field to registration form and then save it to databse. I cannot figure out what might be best way of storing the date in the table. I could convert it to unix epoch time, or I could do YYYYMMDD.
Thoughts? What would be the easiest method of saving the DOB?
I am not asking on how to do it, just the format. Thanks
Hi there, I'm new to PHP so sorry if this is a really basic question. How do i post date of birth collected from a form, into a database? I have the fields in the form set up as 'day' 'month' 'year' all of which are drop-down boxes. I tried doing it one way which i saw on a different website, but it didn't work. Here is what i tried: Code: [Select] '$_POST[day] . - . $_POST[month]' . - . $_POST[year]', More info: In the database table this information is going to, the "date of birth" field is set to "DATE" type. Don't know if that makes any difference hi all,
Firstly I am new to the php language,
hopefully this is not a silly question or a no brainer.
I have looked over my code.. and for some reason when I insert data from a cms into a mySql database thers two fields that swop around..
HERES THE CODE IM WORKING WITH :
<?php //if form has been submitted process it if(isset($_POST['submit'])){ $_POST = array_map( 'stripslashes', $_POST ); //collect form data extract($_POST); //very basic validation if($title ==''){ $error[] = 'Please enter the title.'; } if(!isset($error)){ try { //insert into database $stmt = $handler->prepare('INSERT INTO event_calendar (title,event_date,description) VALUES (:title, :description, :event_date)') ; $stmt->execute(array( ':title' => $title, ':description' => $description, ':event_date' => date('Y-m-d') )); //redirect to index page header('Location: index.php?action=added'); exit; } catch(PDOException $e) { echo $e->getMessage(); } } } //check for any errors if(isset($error)){ foreach($error as $error){ echo '<p class="error">'.$error.'</p>'; } } ?> <form action='' method='post'> <p><label>Title</label> <input type='text' name='title' value='<?php if(isset($error)){ echo $_POST['title'];}?>'></p> <p><label>Description</label><br /> <textarea name='description' cols='50' rows='5'><?php if(isset($error)){ echo $_POST['description'];}?></textarea></p> <p><label>Date of Event : (y-m-d) :</label><input name="event_date" type="date" value='<?php if(isset($error)){ echo $_POST['event_date'];}?>'></p> <p><input type='submit' name='submit' value='Submit'></p> </form>Could anyone please just look through it.. My database structure is simple.. id, title, description, event_date Thanks in advance Currently the date is stored in the database as 28-02-2011 - 21:00:30 and the variable is: $date['mTime'] How can I format it too look "pretty" like this: February 28, 2011 - 10:00 PM? (don't need the seconds) I have the date stored as: date( "d/m/Y" ) After it's pulled from the database, I would like it to display like: date( "F j, Y" ) I have tried below, but the output makes d the month and m the day. $dateStamp = strtotime($row['startrepeat']); $dateFormatted = date("F j, Y", $dateStamp); $day = $_POST['day']; $month = $_POST['month']; $year = $_POST['year']; $date = date("Y-m-d", time(0,0,0,$month, $day, $year)); $sql="INSERT INTO child_info (first_name,middle_name,first_family_name,second_family_name, gender,birthdate,mother_living,father_living,brothers,sisters,resident_time,dorm,school,grade_level,school_subject,speak_english,food,medical_allergies,physical_limits,future,instrument,work,social,special_people,hobby,sponsor) VALUES ('$_POST[first_name]','$_POST[middle_name]','$_POST[first_family_name]','$_POST[second_family_name]','$_POST[gender]','$_POST[date]','$_POST[mother_living]','$_POST[father_living]','$_POST[brothers]','$_POST[sisters]','$_POST[resident_time]','$_POST[dorm]','$_POST[school]','$_POST[grade_level]','$_POST[school_subject]','$_POST[speak_english]','$_POST[food]','$_POST[medical_allergies]','$_POST[physical_limits]','$_POST[future]','$_POST[instrument]','$_POST[work]','$_POST[social]','$_POST[special_people]','$_POST[hobby]','$_POST[sponsor]')"; I'm having problems posting date from my MYSQL database. The date in my database is this "2011-01-08 02:53:14" but the it only echo's "01.01.70" Could someone help me figure out why? Here is my code: Code: [Select] <?php $servername='localhost'; $dbusername='root'; $dbpassword=''; $dbname='store'; connecttodb($servername,$dbname,$dbusername,$dbpassword); function connecttodb($servername,$dbname,$dbuser,$dbpassword) { global $link; $link=mysql_connect ("$servername","$dbuser","$dbpassword"); if(!$link){die("Could not connect to MySQL");} mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error()); } // Get all the data from the "example" table $result = mysql_query("SELECT * FROM henvendelser WHERE status = 'Ubehandlet' ORDER by id desc ") or die(mysql_error()); echo "<table cellspacing='12px' cellpaddomg='5px' align='center'>"; echo "<tr> <th>ID</th> <th> Opprettet </th> <th>Navn</th> <th>Telefon</th> <th>Emne</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array($result)) { $postTime = $row['date']; $thisTime = time(); $timeDiff = $thisTime-$postTime; if($timeDiff <= 604800) { // Less than 7 days[60*60*24*7] $color = '#D1180A'; } else if($timeDiff > 604800 && $timeDiff <= 1209600) { // Greater than 7 days[60*60*24*7], less than 14 days[60*60*24*14] $color = '#D1B30A'; } else if($timeDiff > 1209600) { // Greater than 14 days[60*60*24*14] $color = '#08C90F'; } echo '<tr style="color: '.$color.';">'; echo '<td>'. $row['id'] .'</td>'; echo '<td>'. date('d.m.y', $postTime) .'</td>'; echo '<td><a href="detaljer.php?view='. $row['id'] .'">'. $row['Navn'] .'</a></td>'; echo '<td>'. $row['Telefon'] .'</td>'; echo '<td>'. $row['Emne'] .'</td>'; echo '</tr>'; } echo '</table>'; ?> Hi, I've got a date picker on a form which puts data into a database in the YYYY-MM-DD format. Just wondering how I could also put the name of the month (extracted from that) as well as just the year into separate columns. Ie: To use the field race_date from the form to also fill the 'race_month' and 'race_year' columns in the database. This code obviously only fills the 'race_date' column so far: Code: [Select] global $_POST; $race_date = $_POST["race_date"] ; .... $query = "INSERT INTO 10k_races (race_date, race_month, race_year)" . "VALUES ( '$race_date', '$race_month', '$race_year')"; i have been trying to insert date with when users post there comment but when i echo the date() with the comments..it just display 0000.00.00.00 just like that and when i checked my DB it was like that too..please what can i do.this is my code Thankd in advance Code: [Select] <?php include"header.php"; if(isset($_POST['submit'])) { $postdate=mktime(0,0,0,date("m"),date("d")+1,date("y")); $comment=mysql_real_escape_string($_POST['comment']); if($comment!=='') { $ins="INSERT INTO post(post_content,post_date)VALUES('$comment','$postdate')"; mysql_query($ins) or die(mysql_error()); } else { echo"You can not post an empty page"; } } Hi, I have a problem. i want to show the current date and time in my tables of the database. I want to show it because i want to show it on my report generated in php. By the way i do not have a "date" field in my form. Can anyone help me out? Thanks, Heshan. Hi I don't know exactly what to do to see correct date of birth into my sql database. I have following code i.e. $month=$_POST['month']; $year=$_POST['year']; $date=$_POST['date']; $date_value="$month/$date/$year"; echo"YYYY-mm-dd format:$date_value"; and sql insert statement is like this $sql = "INSERT INTO table_name(fname, lname, gender, add1, add2, city, state, zip, country, email, phone, cellphone, dob, photo1) VALUES('$fname','$lname','$gender','$add1','$add2','$city','$state','$zip','$country','$email','$phone','$cellphone', '$date_value','" . $image['name'] . "')"; I don't know what exactly I need to do? Even though I changed the setting in php ini to register_globals = On I would appreciate any kind of help regarding this matter. Thanks Smita Hi i have a drop down menu for date which is meant to insert all 3 values into a date column bt is only sending the year how can i fix it <select name="date_of_birth"> <option value="1">January <option value="2">February <option value="3">March <option value="4">April <option value="5">May <option value="6">June <option value="7">July <option value="8">August <option value="9">September <option value="10">October <option value="11">November <option value="12">December </select> <select name="date_of_birth"> <option value="1">1 <option value="2">2 <option value="3">3 <option value="4">4 <option value="5">5 <option value="6">6 <option value="7">7 <option value="8">8 <option value="9">9 <option value="10">10 <option value="11">11 <option value="12">12 <option value="13">13 <option value="14">14 <option value="15">15 <option value="16">16 <option value="17">17 <option value="18">18 <option value="19">19 <option value="20">20 <option value="21">21 <option value="22">22 <option value="23">23 <option value="24">24 <option value="25">25 <option value="26">26 <option value="27">27 <option value="28">28 <option value="29">29 <option value="30">30 <option value="31">31 </select> <select name="date_of_birth" id="year"> <?php $year = date("Y"); for($i=$year;$i>$year-50;$i--) { if($year == $i) echo "<option value='$i' selected>Current Year</option>"; else echo "<option value='$i'>$i</option>"; } ?> |