Add to collection
Md Riyazuddin

Md Riyazuddin

Verified

How to insert data using wpdb

You can insert your data via prepare method because prepare help to secure from SQL injection .
And this help to secure insert data in  WordPress .
global $wpdb;
$tablename = $wpdb->prefix . "submitted_form";
$name     = "Kumkum"; //string value use: %s
$phone    = "3456734567"; //numeric value use: %d
$sql = $wpdb->prepare("INSERT INTO `$tablename` (`name , `phone`) values (%s, %d)", $name, $phone);
$wpdb->query($sql);

References and Credits

Tagged with: wordpress

Comments 0

  • Sorry!! No comment posted yet. Become the first user to give comment.
Add a comment

Would you like to write for w3 sniff?

Become part of an amazing group of contributors and authors and start writing for us

Join Now
global $wpdb;
$tablename = $wpdb->prefix . "submitted_form";
$name     = "Kumkum"; //string value use: %s
$phone    = "3456734567"; //numeric value use: %d
$sql = $wpdb->prepare("INSERT INTO `$tablename` (`name , `phone`) values (%s, %d)", $name, $phone);
$wpdb->query($sql);
Feedback submitted successfully.