Adding data to custom database
-
Hi,
I’m trying to put together a form to allow admins to add new courses to a list for users to look at.
It’s a simple HTML form, pushing data to a php file which should in turn add rows to my database.The html form does have to save each result to an array, as there is an option to add more “forms”.(perhaps this is what is screwing it up).
The problem comes when i actually go to submit my form and i get:
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
setup is as follows:
Database name “allcourses”
rows: courseid(autoincremental), coursename, coursevalue, coursecategoryaddnewcourse.php
<?php get_header(); ?> <div id="addcourse"> <form action="https://www.pcwportsmouth.dev/wp-content/themes/asto/insertcourse.php" method="post" id="addcourse"> <label id="coursename">Course Name:<input type="text" name="coursename[]" size="30" /></label> <label id="coursevalue">Points Value:<input type="text" name="coursevalue[]" size="10" /></label> <label id="coursecategory">Course Category:<select name="coursecategory[]" size="1"> <option selected>Product Knowledge</option> <option>Demonstrate Effectively</option> <option>Perfect Your Pitch</option> <option>Business Integration and Technical Training</option> </select></label> <p> </p> <p> </p> </div> <input type="submit" name="Submit" id="addcoursesubmit" value="Submit" /> </form> <a href="" onClick="return false;" id="addform">Add Another Course.</a> <?php get_footer(); ?>
insertcourse.php
<?php global $wpdb; $coursename=$_POST['coursename']; $coursevalue=$_POST['coursevalue']; $coursecategory=$_POST['coursecategory']; $wpdb->insert( 'allcourses', array( 'coursename' => '$coursename', 'coursevalue' => '$coursevalue', 'coursecategory' => '$coursecategory' ), array( '$s', '$d', '$s' ) ); echo "</br>"; echo "<a href\"add-new-asto-course\">Add More Courses</a>" ?>
- The topic ‘Adding data to custom database’ is closed to new replies.