I have a list of calendar events I want to upload into mysql. Some of these events occur weekly and some monthly. Also I want to be able to insert a specific week number along with each row that are inserted.e.g
This part of the code I'm trying to make do what I want is not doing it. No errors are shown on the screen and no rows are inserted into the database.
<?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("January","February","March","April","May","June","July","August","September","October","November","December");
$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){
$query = mysql_query(" INSERT INTO caldemo(day, month, year, eventname, eventtime, eventplace)
VALUES ('".$k."', '".$month[$j]."', '".$year[$i]."', '".$eventname."', '".$eventtime."', '".$eventplace."', )") ;
}
}
}
}
?>
Well the code you have is not entering values into the DB because you have syntax error in your sql. At the very end you have an extra comma after $eventplace.
If you want the week number, you can use mktime to get the timestamp, then date with a 'W' flag to get the week number.
That being said, you may also want to reconsider your tables. Store event information in one table and store every occurrence of an event in another table. This keeps your meta information (name, description, location) separate and from repeating 50 million times in the same table. There's also a few other nice things you get out of it, but for another time.
And like Marc B said, at the very least use a mysql_real_escape_string. As you have it, someone could even inadvertently smash your database up.
There is a Komma Too much After eventplace