Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

php - 发布过帐数据(Issues posting data)

I'm trying to insert data to a Wordpress database from a form using the post method.

(我正在尝试使用post方法将数据从表单插入Wordpress数据库。)

Beofre inserting (code will go where comment is) I'm trying to print the results to screen.

(Beofre插入(代码将进入注释所在的位置)我正在尝试将结果打印到屏幕上。)

When I test my code to collect this data from the form it errors only on one field for some reason.

(当我测试代码以从表单收集此数据时,由于某种原因它仅在一个字段上出错。)

The others post correctly so I'm at a bit of a loss.

(其他人正确地发布,所以我有点茫然。)

Below is the code:

(下面是代码:)

global $mydb;
echo '<form name="newProducts" method="post">';
$output = "<div>";
// array of column names
$table_name = $mydb->prefix . '`my-table-names`';
foreach ( $mydb->get_col( "DESC " . $table_name, 0 ) as $column_name ) {
        if($column_name!='id'){
          $table_name = $mydb->prefix . '`my-table-names`';
           $field_name = $column_name;
           $getSpecColNameOne = $mydb->get_var($mydb->prepare( "SELECT {$field_name} FROM {$table_name} WHERE id=%d", 0));
           $output .= '<div>';
           $output .= '<div>' . $getSpecColNameOne . '</div>';
           $output .= '<div><input name="' . $column_name . '" type="text" value=""></div>';
           $output .= '</div>';
        }   
}

$output .= '</div>'; 
echo $output;
    $_POST = array_map( 'stripslashes_deep', $_POST );
    echo '<div class="btnWrapper">';
    echo '<input class="btn border-width-0 btn-text-skin btn-color-jevc btn-square btn-icon-left adduserBtn" type="submit" name="btnSubmit">';
echo '</form>';

if ($_POST) {

    $skipKeys = array(
                    'btnSubmit',
                    'id',
                 );

foreach($_POST as $key =>$value){

        if(!in_array($key,$skipKeys)){
            ///insert into db here////////
            echo '</br>';
            echo"Key:"; 
            print_r ($key);
            echo '</br>';
            echo"value:"; 
            print_r ($value);
        }
    }
}

The output I get if I don't fill out column_1 looks like this:

(如果不填写column_1,我得到的输出如下所示:)

Key:column_1
value:
Key:column_2
value:Input Test 2
Key:column_3
value:Input Test 3

However, if I fill in data into column_1 input field it errors and I get redirected to a 404 page.

(但是,如果我在column_1输入字段中填写数据,则会出错,并且将我重定向到404页面。)

column_1 html output looks ok:

(column_1 html输出看起来不错:)

<input name="column_1" type="text" value="">

Any ideas appreciated.

(任何想法表示赞赏。)

  ask by kfc06 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...