PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I've got the 2 following programs.. the user first enters "addArticle.php" then upon hitting Submit, goes to the "addToDB.php" program. Login to the server (which is local) works, data is written to the database but to the dateOfArticle column (set as "date" format in the database) just enters "0000-00-00" when I hit Submit. However, hitting "Submit" again and it enters the value I entered in the pulldown menu in the prior screen. Any ideas why? Any fixes?
You're trying to use PHP code to set the date before the user has even entered it. Remember that PHP code is executed on the server before the HTML page is ever sent to the browser. So your code:
can't possibly supply the value after the page is first sent to the browser. You'll have to do that part in Javascript. I didn't take the time to examine your script to confirm this, but probably your POST variables are passing that value on to the next time the script executes, producing the odd result that it updates it the next time.
If the page loads for the first time, $dateOfArticle would be set today's year-today's month-NULL. I can't see where the day is set in your code.
Before panicing, I would probably tend to echo the SQL out so I can see what the database server is seeing. Can you echo the query that you say is not working and post it so we can see the query that MySQL is seeing? Thanks.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Ok, I've updated the code from the "addArticle.php" program to include the Day selection.... the following is what I added there:
INSERT INTO articleTable (articleIDNumber, dateOfArticle, categories, articleTitle, articleText) VALUES ('','2007-7-27','a','b','c')
It's working now, accepting today's date into the database in the dateOfArticle column, but how can I change the code so that if the user doesn't want this default selection and would rather change the date options and Submit it via a form, that selected date will be sent to the database rather than the default date?
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
How can I change the code so that if the user doesn't want this default date selection and would rather change the date options and Submit it via a form, that selected date will be sent to the database rather than the default date?
Its simple, just all user to select the date in the form..... this you can do by giving him three combo i.e day,year and month and let user select the date by himself.
Thanks for the link. That script is perfect. Just trying to figure out now how to have the exported format be numerical values, formatted "yyyy-mm-dd" to incorporate it with the php script so it can send to and query the mysql server. I posted in the respective forum, but wanted to let you know it seems to have solved my problem. Thanks for the help.