PHP - Insert Into Db Datetime And Echo Out Only Date?
What I'm basically trying to accomplish is, that the datetime of the user posted information is registered with the Now() function in the query, BUT that the user entered information gets echo'd out with the Date showing ONLY.
What I have is this: -Just as an example- INSERT INTO db (date_created) VALUES (now()) while ($row = mysqli_fetch_array($data)) { echo '<tr><td>' . $row['date_created'] . '</td></tr>'; } mysqli_close($dbc); With this way of course I get Date and Time showcased just like it's inserted into the DB. What would be a legit way of showcasing just date. Thanks for help. EDIT: or is there a better way than using now() to showcase the date when the user entered information was posted? Similar TutorialsAlright, I have a Datetime field in my database which I'm trying to store information in. Here is my code to get my Datetime, however it's returning to me the wrong date. It's returning: 1969-12-31 19:00:00 $mysqldate = date( 'Y-m-d H:i:s', $phpdate ); $phpdate = strtotime( $mysqldate ); echo $mysqldate; Is there something wrong with it? I'm having trouble inserting a formatted PHP DateTime into a MySQL table. I'm getting: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',2012-01-31)' at line 4 I get the error when I try to insert the date as a string from a DateTime object via: $insertDate = $date->format('Y-m-d'); As well as when I try to recast it as a date object: $insertDate = date("Y-m-d",strtotime($date->format('Y-m-d'))); I've also tried putting the date in ' ' 's and escaped " " 's. My insert query is: $insert = "INSERT INTO pendingordersdetails (PartNumber,Oqty,Pqty,Aqty,PartStatus, PartPrice,idOrderNo,PrtTariffCode,PrtLocation,LineNum,PKqty,SPqty,AllocationDate) VALUES ('$partNum',$oQty,0,$aQty,'Excess',$price,$orderNum,'$tariffCode', '$location',$lineNum,$PKqty,$SPqty,'$allocDate');"; and the echoed output is: INSERT INTO pendingordersdetails (PartNumber,Oqty,Pqty,Aqty,PartStatus, PartPrice,idOrderNo,PrtTariffCode,PrtLocation,LineNum,PKqty,SPqty,AllocationDate) VALUES ('0446535240 ',3,0,1,'Excess',163.89,66,' ', 'A0406E01',2,,,'2012-01-31'); Anyone have any ideas? Hi there,
I'm a bit of a newbie and I have done a search online, but i'm still confused.
I need to search my MYSQL database in a filed named date_mod I need to search for todays date only $date=gmdate("Y-m-d");
But however the field is a datetime option so how can I search only todays date and not both date and time.
Thank you for reading.
SELECT * FROM `booking_tbl` WHERE booking_status = 'Check In' AND departure_date_time = NOW()"I use the datetime datatype for the departure_date_time so i can get data from that data because it checking the date and time but i want it to check on the date from the datetime datatype So how can i get the data only with that date without the time in the mysql datetime datatype I am using the following code to get the third sunday of every month for +6 Months from todays date. I have put together the following code which works perfectly when the date is echoed however when it comes to inserting those dates into mysql db it throws a unable to convert to string error. Im new to this and my head is in a spin as to why those dates can't be inserted if they can echoed ok. I have spent 2 days at it now and searched many forum however they seem to get side tracked from my issue (or do they)??????? I figure I can't go mixing DateTime and date() the way I have? Please help??? Code: [Select] [php] $month=date('F'); $now=date('Y-m-d'); $year=date('Y'); $num='3'; //example only this will be a $_POST value 0-3 $day='Sunday'; //example only this will be a $_POST value Monday-Sunday $start= date('Y-m-d', strtotime('+'.$num.' week '.$day.' '.$month.' '.$year.'')); if($start>$now) { $begin=strtotime('+'.$num.' week '.$day.' '.$month.' '.$year.''); } else { $d = new DateTime( $start ); $d->modify( 'first day of next month' ); $nextmonth = $d->format( 'F' ); $year = $d->format( 'Y' ); $begin=strtotime('+'.$num.' week '.$day.' '.$nextmonth.' '.$year.''); } $date=date('Y-m-d', $begin); # insert into db first occurance //mysql_select_db($database); //$query_rsFirst = "INSERT INTO event_date VALUES (NULL, '$event', '$d', '$date', '$date')"; //$rsFirst = mysql_query($query_rsFirst) or die(mysql_error()); echo $date.'<br/>'; for($i = 0; $i <= 4; $i++) { $d = new DateTime( $date ); $d->modify( 'first day of next month' ); $nextmonth = $d->format( 'F' ); $date=date('Y-m-d', strtotime('+'.$num.' week '.$day.' '.$nextmonth.' '.$year.'')); # insert into db //mysql_select_db($database); //$query_rsDate = "INSERT INTO event_date VALUES (NULL, '$event', '$d', '$date', '$date')"; //$rsDate = mysql_query($query_rsDate) or die(mysql_error()); echo $date.'<br/>'; if($nextmonth=="December") { $d = new DateTime( $date ); $d->modify( 'first day of next year' ); $year = $d->format( 'Y' ); } } [/php] I have a field called date_time in the database which is of type datetime. I have a form which on submit needs to enter the current date and time in the date_time field. I know I can get the current time using time() $time=time(); Can do I do some kind of manipulation using strtotime() and store in the database in datetime format? I am looking for a way to have my 'start_date', echo ('start_date' + 1 month). I am looking at the line that reads .... date("F Y",strtotime($row['start_date'])). Does anyone have a suggestion. The date format read, July 2014 or alphabetical full month, numerical full year. Thank you in advance.
<?php $query = sqlsrv_query($conn, $sql);if ($query === false){ exit("<pre>".print_r(sqlsrv_errors(), true));}while ($row = sqlsrv_fetch_array($query)){ echo "<tr> <td><a href='view_invoice.php?meter_id=$meter_id&subaccount=$subaccount&start_date=$row[start_date]'>$row[meter_id]</a></td> <td>" . date("F Y",strtotime($row['start_date'])) . "<td>$row[invoice_no]</td><td>" . date_format($row['invoice_date'],'Y-m-d') . "<td>$row[amount_paid]</td>" . "<td>$row[payment_date]</td>" . "<td>$row[check_number]</td>" ;}sqlsrv_free_stmt($query); ?> Edited by Butterbean, 11 January 2015 - 08:19 PM. Hi, i insert in db with mysql_real_escape_string() function, but when i read i use this: - htmlentities(stripslashes($value), ENT_QUOTES, "UTF-8") - for all fields but no textarea - stripslashes($value) - for textarea, becouse when insert that textare, its tinymce, and have html tags Is this right way ? This php file cant echo in the 2nd php code, can anyone help me about this? 1st php code to connect into the 2nd php code Code: [Select] <?php $Total = $Total + $Amount; } ?> </tr> <tr> <td colspan="3" align="Right">Total</td> <td align ="Center"><?php echo number_format($Total,2);?></td> </tr> 2nd php code Code: [Select] <?php $db = mysql_connect("localhost", "root", ""); mysql_select_db("vinnex",$db); $TransNo = $_POST['TransNo']; $Username = $_POST['Username']; $Date = $_POST['Date']; $Total = $_GET['Total']; echo $Total; $sqltransaction = " INSERT INTO transaction (TransNo, Username, Date, Total) VALUES ('$TransNo', '$Username', '$Date', '$Total')"; $resulttransaction = mysql_query($sqltransaction); ?> I am echo information from the database now I would like to insert these to different table. I am using checkbox to echo and when the user click on the one of these the result should be saved to a new table. So far I have<?php include 'Database/connection.php'; include 'Database/question_sql.php'; while($info = mysql_fetch_array( $sql )) { echo "{$info['Que_Question']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice1[]\" value=\"{$info['Que_Choice1']}\" /> "; echo "{$info['Que_Choice1']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice2[]\" value=\"{$info['Que_Choice2']}\" /> "; echo "{$info['Que_Choice2']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice3[]\" value=\"{$info['Que_Choice3']}\" /> "; echo "{$info['Que_Choice3']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice4[]\" value=\"{$info['Que_Choice4']}\" /> "; echo "{$info['Que_Choice4']} <br />\n"; } ?> Dear all, how can I convert a string "yyyy-mm-dd hh:mm" into a really datetime value with php? thanks! Sorry for the topic title not explaining much, but I did not now how to word it! I was previous given some code at http://www.phpfreaks.com/forums/php-coding-help/streamlining-dreamweaver-generated-php-code/msg1459677/#msg1459677 that created a header every time a crtieria changed, in this case a players position. I have tried to tailor this to another page but have got it wrong somewhere. In this instance I was a change of date to be the determining factor. For example, with what I have tried so far, the output is 2011-04-02 Lowestoft Town v Tonbridge Angels 2011-04-02 Tooting & Mitcham United v Maidstone United 2011-04-02 Wealdstone v Concord Rangers 2011-04-09 Hastings United v Margate 2011-04-09 AFC Hornchurch v Carshalton Athletic 2011-04-09 Billericay Town v Aveley when I actually want 2011-04-02 Lowestoft Town v Tonbridge Angels Tooting & Mitcham United v Maidstone United Wealdstone v Concord Rangers 2011-04-09 AFC Hornchurch v Carshalton Athletic Billericay Town v Aveley I have tried to adjust the code to reflect the different query etc but something is missing. Thinking further ahead, there will also be a second criteria, in that games in different competitions could be played on the same day so I would also want to group the output by the competition ('comp' in the table) to get 2011-04-02 League Lowestoft Town v Tonbridge Angels Tooting & Mitcham United v Maidstone United Cup Wealdstone v Concord Rangers 2011-04-09 League AFC Hornchurch v Carshalton Athletic Cup Billericay Town v Aveley I would imagine that would just mean drilling down one more level in the code once I get this bit right. The tables, with a sample of data are Code: [Select] CREATE TABLE `all_games` ( `all_games_id` int(11) NOT NULL auto_increment, `date` date default NULL, `time` time default NULL, `comp` int(11) NOT NULL default '1', `round` tinyint(4) default NULL, `replay` char(1) default NULL, `home_team` int(11) NOT NULL default '1', `away_team` int(11) NOT NULL default '1', `home_goals` int(11) default NULL, `away_goals` int(11) default NULL, `home_ht` int(11) default NULL, `away_ht` int(11) default NULL, `attendance` int(11) default NULL, PRIMARY KEY (`all_games_id`) ) TYPE=MyISAM AUTO_INCREMENT=732 ; INSERT INTO `all_games` VALUES (700, '2011-04-23', '00:00:00', 1, NULL, '', 11, 20, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (701, '2011-04-23', '00:00:00', 1, NULL, '', 12, 13, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (702, '2011-04-23', '00:00:00', 1, NULL, '', 15, 22, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (703, '2011-04-23', '00:00:00', 1, NULL, '', 21, 7, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (704, '2011-04-25', '00:00:00', 1, NULL, '', 1, 14, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (705, '2011-04-25', '00:00:00', 1, NULL, '', 4, 6, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (706, '2011-04-25', '00:00:00', 1, NULL, '', 8, 15, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (707, '2011-04-25', '00:00:00', 1, NULL, '', 13, 2, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (708, '2011-04-25', '00:00:00', 1, NULL, '', 16, 21, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (709, '2011-04-25', '00:00:00', 1, NULL, '', 17, 3, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (710, '2011-04-25', '00:00:00', 1, NULL, '', 18, 9, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (711, '2011-04-25', '00:00:00', 1, NULL, '', 19, 5, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (712, '2011-04-25', '00:00:00', 1, NULL, '', 20, 12, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (713, '2011-04-25', '00:00:00', 1, NULL, '', 22, 11, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (714, '2011-04-30', '00:00:00', 1, NULL, '', 14, 18, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (715, '2011-04-30', '00:00:00', 1, NULL, '', 2, 19, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (716, '2011-04-30', '00:00:00', 1, NULL, '', 3, 22, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (717, '2011-04-30', '00:00:00', 1, NULL, '', 5, 13, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (718, '2011-04-30', '00:00:00', 1, NULL, '', 6, 8, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (719, '2011-04-30', '00:00:00', 1, NULL, '', 9, 17, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (720, '2011-04-30', '00:00:00', 1, NULL, '', 11, 7, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (721, '2011-04-30', '00:00:00', 1, NULL, '', 12, 1, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (722, '2011-04-30', '00:00:00', 1, NULL, '', 15, 20, NULL, NULL, NULL, NULL, NULL); INSERT INTO `all_games` VALUES (723, '2011-04-30', '00:00:00', 1, NULL, '', 21, 4, NULL, NULL, NULL, NULL, NULL); CREATE TABLE `competitions` ( `comp_id` int(11) NOT NULL auto_increment, `comp_name` varchar(45) default NULL, `comp_short_name` varchar(4) default NULL, `logo` varchar(255) NOT NULL default '', PRIMARY KEY (`comp_id`) ) TYPE=MyISAM AUTO_INCREMENT=8 ; INSERT INTO `competitions` VALUES (1, 'Isthmian League Premier Division', 'ILP', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/tRymanLeague.png'); INSERT INTO `competitions` VALUES (2, 'FA Cup', 'FAC', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/facup.png'); INSERT INTO `competitions` VALUES (3, 'FA Trophy', 'FAT', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/fattophy.png'); INSERT INTO `competitions` VALUES (4, 'Kent Senior Cup', 'KSC', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/kentseniorcup.png'); INSERT INTO `competitions` VALUES (5, 'Isthmian League Cup', 'ILC', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/isthmianleaguecup.png'); INSERT INTO `competitions` VALUES (6, 'Friendly', 'FR', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/friendly.png'); INSERT INTO `competitions` VALUES (7, 'Kent Messenger Cup', 'KMC', ''); CREATE TABLE `teams` ( `team_id` int(11) NOT NULL auto_increment, `team_name` varchar(45) default NULL, `short_name` varchar(5) default NULL, `badge` varchar(255) default NULL, `year_formed` int(11) default NULL, `nickname` varchar(255) default NULL, `previous_names` varchar(255) default NULL, `website` varchar(255) default NULL, `twitter` varchar(255) default NULL, `facebook` varchar(255) default NULL, `telephone_number` varchar(255) default NULL, `chairman` varchar(255) default NULL, `manager` varchar(255) default NULL, `home_colours` varchar(255) default NULL, `away_colours` varchar(255) default NULL, `stadium` int(11) default NULL, `2009/10` varchar(255) default NULL, PRIMARY KEY (`team_id`) ) TYPE=MyISAM AUTO_INCREMENT=74 ; INSERT INTO `teams` VALUES (1, 'Aveley', 'Ave', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/aveley.png', 1927, 'The Millers', 'None', 'http://www.aveleyfc.net/', NULL, NULL, '01708865940', 'Graham Gennings', 'Alan Kimble', 'Black & Blue/Blue/Blue', 'Black & White/White/White', 3, 'Isthmian League Premier Division, 3rd'); INSERT INTO `teams` VALUES (2, 'Billericay Town', 'Bill', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/billericaytown.png', 1880, 'Ricay, The Blues', 'None', 'http://www.billericaytownfc.co.uk/', 'http://twitter.com/BTFC', 'http://www.facebook.com/billericaytownfc', '01277652188', 'Steve Kent', 'Craig Edwards', 'Blue/White/Blue', 'White/Black/White', 2, 'Isthmian Premier, 13th'); INSERT INTO `teams` VALUES (3, 'Bury Town', 'Bur', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/burytown.png', 1872, 'The Blues', 'Bury St Edmunds, Bury United', 'http://www.burytownfc.co.uk', NULL, NULL, '01277999999', 'Russell Ward', 'Richard Wilkins', 'Blue & Red/Blue/Blue', 'White/Black/White', 10, 'Southern League Division One Midlands, 1st'); INSERT INTO `teams` VALUES (4, 'Canvey Island', 'Can', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/canveyisland.png', 1926, 'The Gulls', 'None', 'http://www.canveyislandfc.com', 'http://twitter.com/CIFC', NULL, NULL, 'George Frost', 'John Batch', 'Yellow/Blue/White', 'White/White/White', 11, 'Isthmian League Premier Division, 16th'); INSERT INTO `teams` VALUES (5, 'Carshalton Athletic', 'Car', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/carshaltonathletic.png', 1905, 'The Robins', 'Mill Lane Misson', 'http://www.carshaltonathletic.co.uk/', 'http://twitter.com/carshaltonath', NULL, '02086428658', 'Harry Driver', 'Mark Butler', 'Red/Red/Red', 'Maroon/White/Maroon', 9, 'Isthmian League Premier Division, 17th'); INSERT INTO `teams` VALUES (6, 'Concord Rangers', 'Con', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/concordrangers.png', 1967, 'Beach Boys', 'None', 'http://www.concordrangers.co.uk/', 'http://twitter.com/ConcordRangers', NULL, '01268691780', 'Antony Smith', 'Danny Scopes / Danny Cowley', 'Yellow/Blue/Blue', 'TBA', 12, NULL); INSERT INTO `teams` VALUES (7, 'Cray Wanderers', 'Cray', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/craywanderers.png', 1860, 'The Wands', 'None', 'http://www.craywands.co.uk', 'http://twitter.com/craywanderers', NULL, '02084605291', 'Gary Hillman', 'Ian Jenkins', 'Amber/Black/Amber', 'Blue/White/White', 13, 'Isthmian League Premier Division, 15th'); INSERT INTO `teams` VALUES (8, 'Croydon Athletic', 'Croy', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/croydonathletic.png', 1986, 'The Rams', 'Wandsworth & Norwood', 'http://croydonathletic.net', NULL, NULL, '0208664834', 'TBA', 'Dave Garland & Bob Langford', 'Maroon & White/Maroon/Maroon', 'Yellow/Blue/Blue', 14, 'Isthmian League Division One South, 1st'); INSERT INTO `teams` VALUES (9, 'Folkestone Invicta', 'Fol', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/folkestoneinvicta.png', 1936, 'Invicta, The Seasiders', 'None', 'http://www.folkestoneinvicta.co.uk/', 'http://twitter.com/FIFC', NULL, '01303257461', 'TBA', 'Neil Cugley', 'Amber/Black/Amber', 'Red/White/Red', 15, 'Isthmian League Division One South, 2nd'); INSERT INTO `teams` VALUES (10, 'Grays Athletic', 'Gra', 'N/A', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); INSERT INTO `teams` VALUES (11, 'Harrow Borough', 'Har', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/harrowborough.png', 1933, 'The Boro, The Reds', 'Roxoinian, Harrow Town', 'http://www.harrowboro.com/', 'http://twitter.com/harrowboro_fc', NULL, '08706091959', 'Peter Rogers', 'David Howell', 'Red/Red/Red', 'White/White/Black', 16, 'Isthmian League Premier Division, 14th'); INSERT INTO `teams` VALUES (12, 'Hastings United', 'Has', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/hastingsunited.png', 1894, 'The Arrows, The U''s', 'Hastings Town, Hastings & St. Leonards', 'http://www.hastingsunitedfc.co.uk/', 'http://twitter.com/hastingsufc', NULL, '01424444635', 'David Walter', 'Tony Dolby', 'Maroon/Maroon/Maroon', 'White/White/White', 17, 'Isthmian League Premier Division, 7th'); INSERT INTO `teams` VALUES (13, 'Hendon', 'Hen', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/hendon.png', 1908, 'The Greens, The Dons', 'Christ Church Hampstead, Hampstead Town, Hampstead, Golders Green', 'http://www.hendonfc.net/', 'http://twitter.com/HendonFC', NULL, '02089083553', 'TBA', 'Gary McCann', 'Green/Green/Green', 'Blue/Blue/Blue', 18, 'Isthmian League Premier Division, 10th'); INSERT INTO `teams` VALUES (14, 'AFC Hornchurch', 'AFC', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/afchornchurch.png', 1923, 'The Urchins', 'Upminster Wanderers, Hornchurch & Upminster', 'http://www.afchornchurch.com/', 'http://twitter.com/AFCHornchurch', 'http://www.facebook.com/AFCHornchurch', '01708220080', 'TBA', 'Colin McBride', 'Red & White/Black/Red', 'Blue & White/Blue/Blue', 1, 'Isthmian League Premier Division, 9th'); INSERT INTO `teams` VALUES (15, 'Horsham', 'Hor', 'http://www.margate-fc.com/edit/news/data/upimages/images/Badges/horsham.png', 1871, 'The Hornets', 'None', 'http://www.hornetsreview.co.uk/', NULL, NULL, '01403266888', 'Kevin Borrett', 'John Maggs', 'Yellow & Green/Yellow/Yellow', 'Blue/Black/White', 19, 'Isthmian League Premier Division,11th'); The query is $all_games = mysql_query("SELECT *, HT.team_name as HomeTeam, VT.team_name as AwayTeam, COMP.comp_short_name as CP FROM all_games JOIN teams as HT ON all_games.home_team = HT.team_id JOIN teams as VT ON all_games.away_team = VT.team_id JOIN competitions as COMP ON all_games.comp = COMP.comp_id ORDER BY date ASC "); if (!$all_games) { die("Query to show fields from table failed"); And the code that echoes the right values, but does not seperate the the dates is if($all_games) { if(mysql_num_rows($all_games)) { $lastdate = 0; while ($row_all_games = mysql_fetch_assoc($all_games)) { // when the date changes output a new heading if($lastdate = $row_all_games['date']) { echo "<h1>".strtoupper($row_all_games['date'])."</h1>"; $lastdate = $row_all_games['date']; } echo $row_all_games['HomeTeam']." v ".$row_all_games['AwayTeam']; } } else { echo "No results!"; } } I must admit that I have tried a few variations but the nearest I have got is for the page to echo "No results!" I may be a fraction off getting it right or a million miles away so if anyone can give any pointers I will be very grateful. Thanks in advance Steve Hello fellow php friends, Im having abit of trouble trying to echo out a statement at certain times of the day. for example how would you echo out 'Good Morning' between the times of 01am to 11.59am then echo out 'Good afternoon' between times of 12pm and 6pm and so on. Please help!!!!! Hello, I want to display a weekly events day and time. This event will always be on Saturday @ 10:45 am however, I want to output: 2011-09-17 10:45 then when that date is passed - I want it to change to the next Saturday: 2011-09-21 10:45 etc. Any ideas? Here is one part of php code. Here I try to show in last 1 month which dates exactly user made orders. When I run the SQL code in command prompt it works. I think problem is in while loop. Thanks beforhand for contribution. $query = "SELECT Date FROM orders WHERE User='$username' and DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= Date;"; $result = mysql_query($query,$link_id) or die (mysql_error()); echo "<table border='1'> <tr> <td> Last 1 month's orders:</td> </tr>"; while($order_date = mysql_fetch_row($result)) { echo "<tr>"; echo "<td>" . $order_date[0] . "</td>"; echo "</tr>"; } echo "</table> 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); Hi, new to php so please excuse the simplicity of my questions. I have a menu list that inserts data into a field, is it possible with php to insert a date into another field dpendent on value? For example: MenuList - Status1, Status, Status3 inserted into tblfieldStatus when selected 3 other fields in same table are Status1DateNow Status2DateNow Status3DateNow If a user selected Status2 from menu then Status2Date would be populated with the date today? Kind regards guys, im having a problem here thats making me crazy im making a system and i want to insert the current date in the mysql. I have the field called 'data' in the DB, but when i make the code to insert all the other fields, including the 'data', its work perfectly... unless that damn date! $query = "INSERT INTO news (id, titulo, mensagem, data) VALUES (NULL, '$titulo', '$mensagem', 'date(\"d/m/Y\")')"; whats wrong with that? its stores in DB as '0000-00-00'. I am trying to insert a date into a mySQL table from html drop downs with php. Right now when I enter the date it goes into the database as 0000-00-00. Can anybody see why it might be doing this? My html: Code: [Select] <label for='birthdate' >Birthdate (Optional):</label><br/> <select name='month' id='month' value='<?php echo $fgmembersite->SafeDisplay('month') ?>'> <option value="01" selected="January">January</option> <option value="02">February</option> <option value="03">March</option> etc... </select> <select name='day' id='day' value='<?php echo $fgmembersite->SafeDisplay('day') ?>'> <option value="01" selected="1">1</option> <option value="02">2</option> <option value="03">3</option> etc... </select> <select name='year' id='year' value='<?php echo $fgmembersite->SafeDisplay('year') ?>'> <option value="2010" selected="2010">2010</option> <option value="2009">2009</option> <option value="2008">2008</option> etc... </select> And my php to collect info: Code: [Select] $formvars['birthdate'] = $this->Sanitize($_POST['year'], $_POST['month'], $_POST['day']); php where I make table: Code: [Select] "birthdate DATE NOT NULL ,". php to insert into mysql: Code: [Select] $insert_query = 'insert into '.$this->tablename.'( name, address, birthdate, sex, program, guide, email, username, password, confirmcode ) values ( "' . $this->SanitizeForSQL($formvars['name']) . '", "' . $this->SanitizeForSQL($formvars['address']) . '", "' . $this->SanitizeForSQL($formvars['birthdate']) . '", "' . $this->SanitizeForSQL($formvars['sex']) . '", "' . $this->SanitizeForSQL($formvars['program']) . '", "' . $this->SanitizeForSQL($formvars['guide']) . '", "' . $this->SanitizeForSQL($formvars['email']) . '", "' . $this->SanitizeForSQL($formvars['username']) . '", "' . md5($formvars['password']) . '", "' . $confirmcode . '" )'; Thank you! 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"; } } |