{"id":3095469,"date":"2012-10-05T21:12:31","date_gmt":"2012-10-05T21:12:31","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/adding-data-to-custom-database\/"},"modified":"2016-08-20T16:10:37","modified_gmt":"2016-08-20T16:10:37","slug":"adding-data-to-custom-database","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/adding-data-to-custom-database\/","title":{"rendered":"Adding data to custom database"},"content":{"rendered":"<p>Hi,<br \/>\nI&#8217;m trying to put together a form to allow admins to add new courses to a list for users to look at.<br \/>\n It&#8217;s a simple HTML form, pushing data to a php file which should in turn add rows to my database.<\/p>\n<p>The html form does have to save each result to an array, as there is an option to add more &#8220;forms&#8221;.(perhaps this is what is screwing it up).<\/p>\n<p>The problem comes when i actually go to submit my form and i get:<br \/>\n<code>Fatal error: Call to a member function insert() on a non-object in C:\\Users\\Jordan\\Documents\\Work\\ASTO\\Website\\www.pcwportsmouth.dev\\wp-content\\themes\\asto\\insertcourse.php on line 9<\/code><\/p>\n<p>setup is as follows:<br \/>\nDatabase name &#8220;allcourses&#8221;<br \/>\nrows: courseid(autoincremental), coursename, coursevalue, coursecategory<\/p>\n<p>addnewcourse.php<\/p>\n<pre><code>&lt;?php get_header(); ?&gt;\n&lt;div id=&quot;addcourse&quot;&gt;\n&lt;form action=&quot;http:\/\/www.pcwportsmouth.dev\/wp-content\/themes\/asto\/insertcourse.php&quot; method=&quot;post&quot; id=&quot;addcourse&quot;&gt;\n\n&lt;label id=&quot;coursename&quot;&gt;Course Name:&lt;input type=&quot;text&quot; name=&quot;coursename[]&quot; size=&quot;30&quot; \/&gt;&lt;\/label&gt;\n&lt;label id=&quot;coursevalue&quot;&gt;Points Value:&lt;input type=&quot;text&quot; name=&quot;coursevalue[]&quot; size=&quot;10&quot;  \/&gt;&lt;\/label&gt;\n&lt;label id=&quot;coursecategory&quot;&gt;Course Category:&lt;select name=&quot;coursecategory[]&quot; size=&quot;1&quot;&gt;\n        &lt;option selected&gt;Product Knowledge&lt;\/option&gt;\n        &lt;option&gt;Demonstrate Effectively&lt;\/option&gt;\n        &lt;option&gt;Perfect Your Pitch&lt;\/option&gt;\n        &lt;option&gt;Business Integration and Technical Training&lt;\/option&gt;\n    &lt;\/select&gt;&lt;\/label&gt;\n\n&lt;p&gt;&amp;nbsp;&lt;\/p&gt;\n&lt;p&gt;&amp;nbsp;&lt;\/p&gt;\n&lt;\/div&gt;\n&lt;input type=&quot;submit&quot; name=&quot;Submit&quot; id=&quot;addcoursesubmit&quot; value=&quot;Submit&quot; \/&gt;\n&lt;\/form&gt;\n&lt;a href=&quot;&quot; onClick=&quot;return false;&quot; id=&quot;addform&quot;&gt;Add Another Course.&lt;\/a&gt;\n\n&lt;?php get_footer(); ?&gt;<\/code><\/pre>\n<p>insertcourse.php<\/p>\n<pre><code>&lt;?php\n\nglobal $wpdb;\n\n$coursename=$_POST[&#039;coursename&#039;];\n$coursevalue=$_POST[&#039;coursevalue&#039;];\n$coursecategory=$_POST[&#039;coursecategory&#039;];\n\n$wpdb-&gt;insert(\n\t\t&#039;allcourses&#039;,\n\t\tarray(\n\t\t\t\t&#039;coursename&#039; =&gt; &#039;$coursename&#039;,\n\t\t\t\t&#039;coursevalue&#039; =&gt; &#039;$coursevalue&#039;,\n\t\t\t\t&#039;coursecategory&#039; =&gt; &#039;$coursecategory&#039;\n\t\t\t),\n\t\t\tarray(\n\t\t\t &#039;$s&#039;,\n\t\t\t &#039;$d&#039;,\n\t\t\t &#039;$s&#039;\n\t\t\t )\n);\n\necho &quot;&lt;\/br&gt;&quot;;\necho &quot;&lt;a href\\&quot;add-new-asto-course\\&quot;&gt;Add More Courses&lt;\/a&gt;&quot;\n\n?&gt;<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-3095469","topic","type-topic","status-closed","hentry","topic-tag-array","topic-tag-database","topic-tag-form","topic-tag-html","topic-tag-sql"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/3095469","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/3095469\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=3095469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}