duancuan7057 2019-08-14 08:52
浏览 54

问题使用Wordpress将数据插入sql

I am trying to insert data in Mysql into a table name wp_stuff. Wordpress didn't show me any error but the data is not being inserted. Where is the error of following code?

<form method="post"> //I also used here action attribute.
    Stuff Name:<input type="text" name="name" id="name"><br><br>
    ....... so on....
    <input type="submit" value="Submit Data">

    </form>

    <?php 
    if(isset($_POST['submit'])){

     global $wpdb;

        $name = $_POST['name'];

        $f_name = $_POST['f_name'];

        ...... so on.....



         $user_details = array('name' => $name, 'f_name' => $f_name, 'm_name' => $m_name, 'b_date' => $b_date, 'gender' => $gender, 'b_group' => $b_group, 'photo' => $photo, 'email' => $email, 'phone' => $phone, 'present_address' => $present_address, 'permanent_address' => $permanent_address, 'nid' => $nid, 'exp' => $exp, 'at' => $at, 'other_file' => $other_file, 'al' => $al, 'u_name' => $u_name, 'password' => $password, 'd_name'=> $d_name, 'in_time' => $in_time, 'out_time' => $out_time, 'j_date' => $j_date, 'salary' => $salary);

        $table_name =$wpdb->prefix."stuff";
        $result = $wpdb->insert($table_name, $user_details, array('%s','%s','%s','%s','%s','%s','%b','%s','%s','%s','%s','%b','%b','%b','%b','%b','%s','%s','%s','%s','%s','%s','%i'));


    };

    ?>
  • 写回答

2条回答 默认 最新

  • dongluo6343 2019-08-14 09:29
    关注

    Try this code. array('%s') format is optional.

    <form method="post"> //I also used here action attribute.
        Stuff Name:<input type="text" name="name" id="name"><br><br>
        ....... so on....
        <input type="submit" value="Submit Data">
    
    </form>
    
    <?php 
    
    if(isset($_POST['submit'])){
    
        global $wpdb;
    
        $name = $_POST['name'];
        $f_name = $_POST['f_name'];
    
        ...... so on.....
    
    
         $user_details = array('name' => $name, 'f_name' => $f_name, 'm_name' => $m_name, 'b_date' => $b_date, 'gender' => $gender, 'b_group' => $b_group, 'photo' => $photo, 'email' => $email, 'phone' => $phone, 'present_address' => $present_address, 'permanent_address' => $permanent_address, 'nid' => $nid, 'exp' => $exp, 'at' => $at, 'other_file' => $other_file, 'al' => $al, 'u_name' => $u_name, 'password' => $password, 'd_name'=> $d_name, 'in_time' => $in_time, 'out_time' => $out_time, 'j_date' => $j_date, 'salary' => $salary);
    
        $table_name =$wpdb->prefix."stuff";
        $result = $wpdb->insert($table_name, $user_details);
    
    };
    
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用