Jump to content

[SOLVED] Date problem - selecting month in form then querying it


Recommended Posts

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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