I use the following code to try and return the name of the day for a given date by a MySQL query...and it don't work.
It works when I do the MySQL query directly but not with PHP. Please consider:
(I replaced the MySQL host, username, database and pass here-- but I KNOW they are correct in my code)
...Do I need to specify a database in my query, e.g.Code:<html> <head> <title>Test the date</title> </head> <body> <form action="<?php $_SERVER[PHP_SELF] ?>" method="POST"> Type the date in YYYY-MM-DD format: <input type="text" name="date"> <input type="submit" value="get info"> </form> <?php $mysqlconn = mysql_connect("myhost", "myusername", "mypass"); mysql_select_db("mydatabase", $mysqlconn); if (!isset($_POST[date])) { print "Enter a date..."; } else { $date = $_POST[date]; print "Info for $date:"; print "<br />"; $dayname = "SELECT dayname('$date')"; print "The day of week of this date is: "; $daynamequery = mysql_query($dayname, $mysqlconn); } ?> </body> </html>
$dayname = "SELECT dayname('$date') FROM 'database'"; ???
Please note I also know that $date is in the correct format for the mysql query YYYY-MM-DD.
Edit: here is the link where the script is run: http://captainscall.site11.com/page_...estthedate.php
Thanks,
Doug


Reply With Quote
Bookmarks