{"id":1056,"date":"2022-08-30T15:11:39","date_gmt":"2022-08-30T15:11:39","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/undefined-index-for-php-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:11:39","modified_gmt":"2022-08-30T15:11:39","slug":"undefined-index-for-php-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/undefined-index-for-php-collection-of-common-programming-errors\/","title":{"rendered":"undefined index for PHP-Collection of common programming errors"},"content":{"rendered":"<p>hello people i am doing a function with calendar using AJAX and PHP<\/p>\n<pre><code>$showmonth = $_POST['showmonth'];\n$showyear = $_POST['showyear'];\n$pre_days = date ('w', mktime(0,0,0, $showmonth, 1, $showyear));\n$post_days = (6 - (date('w', mktime(0, 0, 0, $showmonth, $day_count, $showyear))));\n<\/code><\/pre>\n<p>I keep getting error messages saying:<\/p>\n<blockquote>\n<p>Notice: Undefined index: showmonth in C:\\xampp\\htdocs\\calendar_start.php on line 2<\/p>\n<p>Notice: Undefined index: showyear in C:\\xampp\\htdocs\\calendar_start.php on line 3<\/p>\n<p>Warning: cal_days_in_month() expects parameter 2 to be long, string given in C:\\xampp\\htdocs\\calendar_start.php on line 8<\/p>\n<p>Warning: mktime() expects parameter 4 to be long, string given in C:\\xampp\\htdocs\\calendar_start.php on line 9<\/p>\n<p>Warning: mktime() expects parameter 4 to be long, string given in C:\\xampp\\htdocs\\calendar_start.php on line 10<\/p>\n<\/blockquote>\n<p>I think it has something to do with my AJAX java script but i just dont know what there more parts to the AJAX code but i think this is the part troubling me<\/p>\n<pre><code>function next_month() {\n    var nextmonth = showmonth + 1;\n    if(nextmonth &gt;12) {\n        nextmonth = 1;\n        showyear = showyear + 1;\n        }\nshowmonth = nextmonth;\nvar hr = new XMLHttpRequest();\nvar url = \"calendar_start.php\";\nvar vars = \"showmonth=\"+showmonth+\"&amp;showyear=\"+showyear;\nhr.open(\"POST\",url,true);\nhr.setRequestHeader(\"Content-type\", \"application\/x-www-form-urlencoded\");\nhr.onreadystatechange = function() {\n    if(hr.readyState == 4 &amp;&amp; hr.status == 200) {\n        var return_data = hr.responseText;\n        document.getElementById(\"showCalendar\").innerHML = return_data;\n        }\n}\n    hr.send(vars);\n    document.getElementById(\"showCalendar\").innerHTML = \"processing...\";\n}\n\n<\/code><\/pre>\n<p>this maybe the problem too:<\/p>\n<pre><code>function initialCalendar() {\nvar hr = new XMLHttpRequest();\nvar url = \"calendar_start.php\";\nvar currentTime = new Date();\nvar month = currentTime.getMonth() + 1;\nvar year = currentTime.getFullYear();\nshowmonth = month;\nshowyear = year;\nvar vars = \"showmonth=\"+showmonth+\"&amp;showyear=\"+showyear;\nhr.open(\"POST\", url, true);\nhr.setRequestHeader(\"Content-type\", \"application\/x-www-form-urlencoded\");\nhr.onreadystatechange = function() {\n    if(hr.readyState == 4 &amp;&amp; hr.status == 200) {\n        var return_data = hr.responseText;\n        document.getElementById(\"showCalendar\").innerHML = return_data;\n        }\n}\n    hr.send(vars);\n    document.getElementById(\"showCalendar\").innerHTML = \"processing...\";\n}\n<\/code><\/pre>\n<ol>\n<li>\n<p>Are you sending and receiving parameters using same method(POST\/GET)&#8230;? if not so..it may give undefined index error&#8230; i.e. if your sending parameters using GET and receiving parameters using POST or vice versa..<\/p>\n<\/li>\n<li>\n<p>If you change this in your javascript???<\/p>\n<pre><code>var url = \"calendar_start.php\";\nvar vars = \"showmonth=\"+showmonth+\"&amp;showyear=\"+showyear;\nvar final_url = url+\"?\"+vars;\nalert(final_url); \/\/this line should a message with the url, post it please.\nhr.open(\"GET\",final,true);\n<\/code><\/pre>\n<p>That should works.<\/p>\n<p>PS: You pass your url with get params so in you php file you should receive them like<\/p>\n<pre><code>$showmonth = $_GET['showmonth']; \/\/I change POST by GET\n$showyear = $_GET['showyear']; \/\/DONT forget to chenge this in your php file\n<\/code><\/pre>\n<p>Saludos \ud83d\ude09<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:20:05. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>hello people i am doing a function with calendar using AJAX and PHP $showmonth = $_POST[&#8216;showmonth&#8217;]; $showyear = $_POST[&#8216;showyear&#8217;]; $pre_days = date (&#8216;w&#8217;, mktime(0,0,0, $showmonth, 1, $showyear)); $post_days = (6 &#8211; (date(&#8216;w&#8217;, mktime(0, 0, 0, $showmonth, $day_count, $showyear)))); I keep getting error messages saying: Notice: Undefined index: showmonth in C:\\xampp\\htdocs\\calendar_start.php on line 2 Notice: Undefined [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1056","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1056","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1056"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1056\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1056"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1056"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1056"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}