update query last get_col error consulta codex php wordpress wpdb

php - query - Cómo insertar datos usando wpdb



wpdb last error (7)

Problema en tu SQL :

Puedes construir tu sql así:

$wpdb->prepare( "INSERT INTO `wp_submitted_form` (`name`,`email`,`phone`,`country`,`course`,`message`,`datesent`) values (''$name'', ''$email'', ''$phone'', ''$country'', ''$course'', ''$message'', ''$datesent'')" );

También puede usar $wpdb->insert()

$wpdb->insert(''table_name'', input_array())

He escrito como sigue

$name="Kumkum"; $email="[email protected]"; $phone="3456734567"; $country="India"; $course="Database"; $message="hello i want to read db"; $now = new DateTime(); $datesent=$now->format(''Y-m-d H:i:s''); global $wpdb; $sql = $wpdb->prepare( "INSERT INTO `wp_submitted_form` (`name`,`email`,`phone`,`country`,`course`,`message`,`datesent`) values (" $name, $email, $phone, $country, $course, $message, $datesent. '')")''; $wpdb->query($sql);

No funciona ... Arroja un error ... Por favor, ayúdame a corregirlo.


Simplemente use wpdb->insert(tablename, coloumn, format) y wp preparará esa consulta

<?php global $wpdb; $wpdb->insert("wp_submitted_form", array( "name" => $name, "email" => $email, "phone" => $phone, "country" => $country, "course" => $course, "message" => $message, "datesent" => $now , )); ?>


Tienes que verificar tus quotes correctamente

$sql = $wpdb->prepare( "INSERT INTO `wp_submitted_form` (`name`,`email`,`phone`,`country`,`course`,`message`,`datesent`) values ($name, $email, $phone, $country, $course, $message, $datesent)"); $wpdb->query($sql);

O puedes usar like,

$sql = "INSERT INTO `wp_submitted_form` (`name`,`email`,`phone`,`country`,`course`,`message`,`datesent`) values ($name, $email, $phone, $country, $course, $message, $datesent)"; $wpdb->query($sql);

Lee http://codex.wordpress.org/Class_Reference/wpdb


Use $wpdb->insert() .

$wpdb->insert(''wp_submitted_form'', array( ''name'' => ''Kumkum'', ''email'' => ''[email protected]'', ''phone'' => ''3456734567'', // ... and so on ));


Prueba esto

Hace poco me incliné por $wpdb->prepare HERE y agregarlo a nuestro plugin de reserva de clase gratuita, el complemento aprobado en wordpress.org y que pronto estará disponible:

global $wpdb; $tablename = $wpdb->prefix . "submitted_form"; $name = "Kumkum"; //string value use: %s $email = "[email protected]"; //string value use: %s $phone = "3456734567"; //numeric value use: %d $country = "India"; //string value use: %s $course = "Database"; //string value use: %s $message = "hello i want to read db"; //string value use: %s $now = new DateTime(); //string value use: %s $datesent = $now->format(''Y-m-d H:i:s''); //string value use: %s $sql = $wpdb->prepare("INSERT INTO `$tablename` (`name`, `email`, `phone`, `country`, `course`, `message`, `datesent`) values (%s, %s, %d, %s, %s, %s, %s)", $name, $email, $phone, $country, $course, $message, $datesent); $wpdb->query($sql);

Gracias -Frank


$wpdb->query("insert into ".$table_name." (name, email, country, country, course, message, datesent) values (''$name'',''$email'', ''$phone'', ''$country'', ''$course'', ''$message'', )");


global $wpdb; $insert = $wpdb->query("INSERT INTO `front-post`(`id`, `content`) VALUES (''$id'', ''$content'')");