I’m trying the code below to enter events into MySQL table using PHP. When I run it, it gives no error and no row is inserted into MySQL table. Where am I going wrong in the code?
Also when I change
$date = strtotime("third friday of $month[$j] $year[$i]");
to
$date = mktime(0,0,0,$month[$j],$k,$year[$i]);
it works for all days, but I’m looking for only third friday of every month..
<?php
if(isset($_POST['myform'])){
$day = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
$month = array('1','2','3','4','5','6','7','8','9','10','11','12');
$year = array('2011', '2012','2013', '2014', '2015', '2016');
$startday = $_POST['day'];
$eventplace = $_POST['eventplace'];
$eventname = $_POST['eventname'];
$eventtime = $_POST['eventtime'];
for($i=0; $i<count($year); $i++){
for($j=0; $j<count($month); $j++){
for($k=$startday; $k<count($day); $k = $k + 7){
$date = strtotime("third friday of $month[$j] $year[$i]");
$week = date('W', $date) ;
$query = mysql_query(" INSERT INTO caldemo(day, month, year, eventname, eventtime, eventplace, eventweek)
VALUES ('".$k."', '".$month[$j]."', '".$year[$i]."', '".$eventname."', '".$eventtime."', '".$eventplace."', '".$week."' )")or die(mysql_error()) ;
}
}
}
}
?>
<form name="theform" method="post" action="caldemo.php">
<table>
<tr>
<tr>
<td>Event Venue:</td>
<td><input type="text" name="eventplace" size="50"></td>
</tr>
<tr>
<td>Event Name:</td>
<td><input type="text" name="eventname" size="50"></td>
</tr>
<tr>
<td>Event Time:</td>
<td><input type="text" name="eventtime" size="50"></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="Send" name="myform">
</form>
Try
Removed the third
forloop. Changed the argument tostrtotimeand useddayreturned by it as$kin the query.