silvia zulinka
silvia zulinka

Reputation: 731

how to select where month in mysql and php?

How to select where month in mysql and php ?

SELECT * FROM `myTable` WHERE insert_date=MONTH($_POST['month']);

Type insert_date = datetime

here code for input post month:

<select name="month">
<option value="" selected>Choose Month :</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">Maret</option>
<option value="4">April</option>
<option value="5">Mei</option>
<option value="6">Juny</option>
<option value="7">July</option>
<option value="8">Augustus</option>
<option value="9">September</option>
<option value="10">Oktober</option>
<option value="11">November</option>
<option value="12">Desember</option>
</select>

Upvotes: 0

Views: 138

Answers (2)

Sebastian
Sebastian

Reputation: 496

  1. Do not use $_POST directly. At least use (int) $_POST['month']
  2. If insert_date is a date or timestamp field, use WHERE MONTH(insert_date) = :month with :month bind as (int) $_POST['month']

Upvotes: 1

user3441151
user3441151

Reputation: 1910

Query should be like this

SELECT * FROM myTable WHERE MONTH(insert_date)=$_POST['month'];

Upvotes: 2

Related Questions