Nikx Nikx - 2 years ago 99
MySQL Question

Insert Data Into Wordpress Database Table From Custom Form

I am trying to insert the data into wordpress database by creating table. I have created the table but when I try to insert the data from form. It doesnot insert the data. I have checked the database connections. It is working well but the insertion doesnot happen. Can someone help me on this? Here is my code:-

global $wpdb;

$wpdb->insert( 'wp_post_job', array( 'organizationname' =>
$_POST['organizationname'], 'post' => $_POST['post'], 'publishfrom' =>
$_POST['publishfrom'], 'publishupto' => $_POST['publishupto'],
'qualification1' => $_POST['qualification1'], 'qualification2' =>
$_POST['qualification2'], 'qualification3' => $_POST['qualification3'],
'qualification4' => $_POST['qualification4'], 'experience1' =>
$_POST['experience1'], 'experience2' => $_POST['experience2'],
'experience3' => $_POST['experience3'], 'training1' => $_POST['training1'], 'training2' => $_POST['training2'], 'training3' => $_POST['training3'],
'training4' => $_POST['training4'], 'training5' => $_POST['training5'] ),
array( '$s', '$s', '$s', '$s', '$s', '$s', '$s', '$s', '$s', '$s', '$s', '$s', '$s', '$s', '$s', '$s' ) );

Template Name: Form
<?php global $pc_theme_object; /* Reference theme framework class */ ?>
<?php get_header(); ?>

<form action="" id="postjob" method="post">
<td><label for="organizationname">Organization Name:</label></td>
<td><input type="text" name="organizationname" id="organizationname" value="/></td>
<td><label for="post">Post:</label></td>
<td><input type="text" name="post" id="post" value="" /></td>
<td><label for="publishfrom">Publish From:</label></td>
<td><input type="text" name="publishfrom" id="publishfrom" /></td>
<td><label for="publishupto">Publish Upto:</label></td>
<td><input type="text" name="publishupto" id="publishupto" /></td>
<td><label for="qualification">Qualification:</label></td>
<td><input type="text" name="qualification1" id="qualification1" /></td>
<td><input type="text" name="qualification2" id="qualification2" /></td>
<td><input type="text" name="qualification3" id="qualification3" /></td>
<td><input type="text" name="qualification4" id="qualification4" /></td>
<td><label for="experience">Experience:</label></td>
<td><input type="text" name="experience1" id="experience1"/></td>
<td><input type="text" name="experience2" id="experience2"/></td>
<td><input type="text" name="experience3" id="experience3"/></td>
<td><label for="training">Training:</label></td>
<td><input type="text" name="training1" id="training1" />></td>
<td><input type="text" name="training2" id="training2" /></td>
<td><input type="text" name="training3" id="training3" /></td>
<td><input type="text" name="training4" id="training4" /></td>
<td><input type="text" name="training5" id="training5" /></td>
<td><button type="submit" name="submit">Submit</button></td>

<?php get_footer(); ?>

Answer Source

Replace '$s' with '%s'

Use This

if ( isset( $_POST['submit'] ) ){
    $wpdb->insert( 'wp_post_job', array(
        'organizationname' => $_POST['organizationname'], 
        'post' => $_POST['post'],
        'publishfrom' => $_POST['publishfrom'], 
        'publishupto' => $_POST['publishupto'],
        'qualification1' => $_POST['qualification1'], 
        'qualification2' => $_POST['qualification2'], 
        'qualification3' => $_POST['qualification3'],
        'qualification4' => $_POST['qualification4'], 
        'experience1' => $_POST['experience1'], 
        'experience2' => $_POST['experience2'],
        'experience3' => $_POST['experience3'], 
        'training1' => $_POST['training1'], 
        'training2' => $_POST['training2'], 
        'training3' => $_POST['training3'],
        'training4' => $_POST['training4'], 
        'training5' => $_POST['training5'] ),
        array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download