2013-02-23 3 views
0

내가워드 프레스 MySQL의 오류

내가 PHP와 MySQL과

그래서 내가이 양식

<?php 

    /* 
    Template name: mail form 
    */ 
// if using a custom function, you need this 
$Email = $_POST['email-form']; 
$firstn = $_POST['First-name']; 


    global $wpdb; 
    $table_name = $wpdb->prefix . "new_mail_form"; 
    $wpdb->insert($table_name, array('email' => $Email, 'name' => $firstn)) 


    ?> 

    <form method="post" action="#" enctype="multipart/form-data" id="Submitform" > 

<fieldset class="email-form"> 
    <label for="email-form">:</label> 
    <input type="text" name="email-form" id="email-form" placeholder="Enter Your Email here" /> 

</fieldset> 

    <fieldset class="First-name"> 
    <label for="First-name">:</label> 
    <input type="text" name="First-name" id="First-name" placeholder="Enter Your Name here" /> 

</fieldset> 
    < input type="submit" value="Publish Post" tabindex="40" id="submit" name="submit" class="submitbutton" /> 
    </form> 

을 만들기 위해 관리하는 메일 구독 일을 필요로 여기에 초보자입니다 그러나 문제는 모든에 그입니다 페이지를 새로 고침 누군가가 페이지를로드 할 때 내 SQL의 항목이

그래서 자동으로 빈 항목을 추가 추가

어떻게해야합니까?/

답변

1

양식이 먼저 제출되는지 확인하지 않으셔도됩니다. 사용해보기 :

if (!empty($_POST)) { 
    $Email = $_POST['email-form']; 
    $firstn = $_POST['First-name']; 

    global $wpdb; 
    $table_name = $wpdb -> prefix . "new_mail_form"; 
    $wpdb -> insert($table_name, array('email' => $Email, 'name' => $firstn)); 
}