Inserting data through form in database
-
So i’m trying to create a plugin and i want to insert data inside a specified table in the database through a form. Now, the code is giving me no errors and I setup the connection with the database successfully, but for some reason it wont pass through the data. Here’s my code, can anyone tell me whats the issue here. Any help would be deeply appreciated.
Thankyou!
Note : I’m using wamp and working on localhost.
<?php require_once('C:\wamp64\www\wordpress\wp-config.php'); if ( isset( $_POST['save'] ) ){ global $wpdb; $tablename=$wpdb->prefix.'vendor_details'; $data=array( 'shopname' => $_POST['shopname'], 'shoptype' => $_POST['shoptype'], 'area' => $_POST['area'], 'city' => $_POST['city'], 'shopaddress' => $_POST['shopaddress'], 'firstname' => $_POST['firstname'], 'lastname' => $_POST['lastname'], 'emailid' => $_POST['emailid'], 'contact' => $_POST['contact']); $wpdb->insert( $tablename, $data); } ?> <?php get_header(); // Template Name: vendor-login ?> <div class="container"> <div class="row cust-row"> <div class="col-sm-12"> <form action="" id="postjob" method="post"> <table> <tr> <td><label for="shopname">Shop Name</label></td> <td><input type="text" name="shopname" id="shopname" value=""/></td> </tr> <tr> <td><label for="shoptype">Shop Type</label></td> <td><input type="text" name="shoptype" id="shoptype" value="" /></td> </tr> <tr> <td><label for="area">Area</label></td> <td><input type="text" name="area" id="area" /></td> </tr> <tr> <td><label for="city">City</label></td> <td><input type="text" name="city" id="city" /></td> </tr> <tr> <td><label for="shopaddress">Shop Address</label></td> <td><input type="text" name="shopaddress" id="shopaddress" /></td> </tr> <tr> <td><label for="firstname">First Name</label></td> <td><input type="text" name="firstname" id="firstname"/></td> </tr> <tr> <td><label for="lastname">Last Name</label></td> <td><input type="text" name="lastname" id="lastname" /></td> </tr> <tr> <td><label for="Email">Email</label></td> <td><input type="text" name="emailid" id="emailid" /></td> </tr> <tr> <td><label for="lastname">Contact</label></td> <td><input type="text" name="contact" id="contact" /></td> </tr> <tr> <td><button type="submit" name="save">Submit</button></td> </tr> </table> </form> </div> </div> </div> <?php get_footer();?>
- The topic ‘Inserting data through form in database’ is closed to new replies.