2017-03-05 23 views
0

我做了一個自定義的WordPress頁面,我試圖做一個simle窗體並將數據插入到數據庫。試圖讓簡單的WordPress的自定義頁面PHP插入工作

我有2個問題。 1.我的代碼是否插入到自定義頁面的正確位置? 2.這個例子(在這個論壇上發現)給了我一個http 500錯誤。我已經試圖解決它很多天了。請有人可以幫助:)

<?php /* Template Name: Storfanger_indberet */ ?> 
<?php 
if (! defined('ABSPATH')) exit; 
get_header(); ?> 
<div id="primary" <?php generate_content_class();?>> 
<main id="main" <?php generate_main_class(); ?>> 
<?php do_action('generate_before_main_content'); ?> 
<?php while (have_posts()) : the_post(); ?> 
<?php get_template_part('content', 'page'); ?> 
<!--My code begin --> 
<?php 
If($_POST['Submit']) { 
// run validation if you're not doing it in js 
global $wpdb; 
$coursename=$_POST['coursename']; 
$coursename1=$_POST['coursevalue']; 
$coursecategory=$_POST['coursecategory']; 
if($wpdb->insert(
'ct_storfanger_indberetninger', 
array(
'name' => $coursename, 
'email' => $coursename1, 
'message' =>$coursecategory 
) 
) == false) wp_die('Database Insertion failed'); else echo 'Database 
insertion successful<p />'; 
?> 
<a href="" onClick="return false;" id="addcatch">Indberet endnu en fangst.</a> 
<?php 
        } 
else // else we didn't submit the form, so display the form 
{ 
?> 

<form action="" method="post" id="addcatch"> 
<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="addcatch">Add Another Course.</a> 
       <?php 
       } // end else no post['submit'] 
       { 
       ?> 

       <!--My code ends --> 

       <?php 
       // If comments are open or we have at least one comment, load up the comment template 
       if (comments_open() || '0' !=get_comments_number()) : ?> 
        <div class="comments-area"> 
         <?php comments_template(); ?> 
        </div> 
       <?php endif; ?> 

      <?php endwhile; // end of the loop. ?> 
      <?php do_action('generate_after_main_content'); ?> 
     </main><!-- #main --> 
    </div><!-- #primary --> 

    <?php 
    do_action('generate_sidebars'); 
    get_footer(); 
    ?> 
+0

[參考? - 這是什麼錯誤PHP意味着]的可能的複製(http://stackoverflow.com/questions/ 12769982/reference-what-do-this-error-mean-in-php) – Sumurai8

+0

特別是我注意到'// end else'附近沒有提交['submit']''的語法錯誤。 – Sumurai8

+0

我在自己的代碼中發現了這個問題。 – KristianC

回答

相關問題