lokie538 Posted April 25, 2008 Share Posted April 25, 2008 Hi, I have a date that is shown in a text field on a form. Now im trying to update it, but im not sure how. In the text field on the form the date is shown in the format 2007/12/03 and to update it im just thinking that they can change the 2007 to 2008 or whatever. im using this script to update and the collum is in date format. $query2 = "UPDATE studhpe1 SET Date_Enrolled= '{$_POST['date1']}' WHERE StudentID = '{$_POST['studentid']}'"; $result2 = mysqli_query($cxn,$query) or die ("Couldnt execute query."); is there a way to update dates?? and how should I do it? I may have the whole wrong approach. Thanks in advance, Lokie538 Quote Link to comment Share on other sites More sharing options...
lokie538 Posted April 25, 2008 Author Share Posted April 25, 2008 BuMp! lol Quote Link to comment Share on other sites More sharing options...
TEENFRONT Posted April 25, 2008 Share Posted April 25, 2008 confused. Are you wanting to update the date? or checking to see if people can update it, as you dont want them to update it? If its the latter, hide the form field with the HIDDEN attribute. other than that, i misunderstand what your trying to do? Quote Link to comment Share on other sites More sharing options...
lokie538 Posted April 25, 2008 Author Share Posted April 25, 2008 im just trying to update a date in mysql, but why i use the update syntax it doesnt work. Is there a specific syntax i need to use to update a date collum.? Quote Link to comment Share on other sites More sharing options...
TEENFRONT Posted April 25, 2008 Share Posted April 25, 2008 is the msql date field actually set to be a date/time field? or just a plain text field? if its a specific date/time field then yes you need to insert the date/time in the correct format. if its just plaint text then you can insert whatever date. Whats the error you get? Quote Link to comment Share on other sites More sharing options...
lokie538 Posted April 25, 2008 Author Share Posted April 25, 2008 The field is in the date format. not just a text field. The date im trying to update is in the format y/m/d which is the format it is retreived as. When i use the code below all i get is "Couldnt execute query" $query2 = "UPDATE table SET Date_Enrolled='" . $_POST[date1] . "' WHERE ID ='" . $_POST[tid] . "'"; $result2 = mysqli_query($cxn,$query2) or die ("Couldnt execute query2."); Yeah i dunno why its not working, something to do with the wrong format? Quote Link to comment Share on other sites More sharing options...
TEENFRONT Posted April 25, 2008 Share Posted April 25, 2008 debug time then lol or die (mysqli_error ()); instead of or die ("Couldnt execute query2."); post the error Quote Link to comment Share on other sites More sharing options...
TEENFRONT Posted April 25, 2008 Share Posted April 25, 2008 The DATE mysql field format is YYYY-MM-DD So could be wrong format issue. Quote Link to comment Share on other sites More sharing options...
lokie538 Posted April 27, 2008 Author Share Posted April 27, 2008 so how do i change the format? lol Quote Link to comment Share on other sites More sharing options...
AndyB Posted April 27, 2008 Share Posted April 27, 2008 so how do i change the format? lol lol indeed. You can't change the format of a date field, it's yyyy-mm-dd and that's it. I suspect what you really want to concentrate on is how to convert some text format of 'date' as entered by a user (which makes the date format beyond your control - bad idea) and display the database information for date in some preferred 'friendly/local' format. Quote Link to comment Share on other sites More sharing options...
lokie538 Posted May 1, 2008 Author Share Posted May 1, 2008 So how do I get a date from the database, show it on a form, and if its changed store it back in the database? any ideas guys? Sorry I dont know how to do it AndyB. Thanks in advance, Lokie538 Quote Link to comment Share on other sites More sharing options...
lokie538 Posted May 4, 2008 Author Share Posted May 4, 2008 bump Quote Link to comment Share on other sites More sharing options...
lokie538 Posted May 4, 2008 Author Share Posted May 4, 2008 i found the prob, thanks guys Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.