Jump to content

Help with PHP and MySQL


manuelgod

Recommended Posts

I haven't had much experience with php and mysql, so I am asking for help on how to do the following in php:

 

I have 4 fields that I created :

 

start_date varchar(30);

comments varchar(200);

notify_user varchar(5);

birthdate varchar(20);

 

Now SOME records have been filled with the correct values BUT some values in some records have now() as a value instead of the actual

data, in this example start_date.

 

I want to change only the values in start_date that have the now() value to an actual date like :  1985/12/30

 

Can anyone show me a good example script on how to do this ?

 

Thanks in advance guys !

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/39367-help-with-php-and-mysql/
Share on other sites

Yes you can change the data type anytime.  However, you might have to correct the existed values in the table.  You can use phpmyadmin or mysql administrator (local server) to do that.

 

The reason why it is better to use date instead of varchar to store date is because with date format, you can do many thing with it, like comparing date, validation date, subtract, add... you name it.  It is also much for efficient to query.

 

 

 

If i understand correctly, you have some fields that were stored with the string "now()" instead of the actual date. I'm pretty sure you can't replace the now() with the date it was supposed to have entered, but you can certainly update it with the current date.

 

Run the sql: "UPDATE `tablename` SET `start_date` = now() WHERE `start_date` = 'now()'"

 

Make sure that when you use now() from now on that it is not contained in quotes. The quotes will make it a string and mysql will store the string "now()" instead of the functions result.

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.