Jump to content

[SOLVED] Updating a date with php and mysql?


lokie538

Recommended Posts

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

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?

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?

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.