jeff5656 Posted October 22, 2009 Share Posted October 22, 2009 Ok here's my form: <form name="month" method="post" action="displayactive.php"> <select name = "month" > <option selected="" value="">--Select--</option> <option value = "01">January</option> <option value = "02">February</option> <option value = "03">March</option> <option value = "04">April</option> <option value = "05">May</option> <option value = "06">June</option> <option value = "07">July</option> <option value = "08">August</option> <option value = "09">September</option> <option value = "10">October</option> <option value = "11">November</option> <option value = "12">December</option> </select> <input type="submit" value="Change Month" /> </form> I store this at the top of the page in a session and define $month: <?php if(isset($_POST['month'])) { $_SESSION['month'] = $_POST['month']; $month = $_POST['month']; } elseif (isset($_SESSION['month'])) { $month = $_SESSION['month']; } else { $month = date('m'); $monthname = date ("M"); $year= date("Y"); } But when I run this query I get the error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY calldate' at line 1 After it his the query: $query = "SELECT * FROM callsched WHERE service = '$service' AND MONTH(calldate)=$month AND YEAR(calldate)=$year ORDER BY calldate "; So I'm not sure how to take the value of the month in the form and turn it into a month that the query can understand. Link to comment https://forums.phpfreaks.com/topic/178625-solved-date-problem-selecting-month-in-form-then-querying-it/ Share on other sites More sharing options...
cags Posted October 22, 2009 Share Posted October 22, 2009 Best guess, $year doesn't have a value. You only seemingly set $year if $_POST['month'] and $_SESSION['month'] is not set. Try echo'ing out your SQL string before running the query. Link to comment https://forums.phpfreaks.com/topic/178625-solved-date-problem-selecting-month-in-form-then-querying-it/#findComment-942158 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.