After reading the posts with similar problems with $wpdb->insert
I can't find the proper solution for my problem.
I have a template page where I send (via POST) the data to another template page to add rows to a custom table in wordpress database.
One of the values comes from a select, which one is received and processed unless it is not the last option of the select. So weird, I’ve enabled the wpdb->show_Errors()
and when the last option is selected it shows:
WordPress database error: [] SHOW FULL COLUMNS FROM `pagos`.
This only happens when I choose the last option of my select, I made it work adding an extra option in the last place and hiding it but is not a proper solution. Here is my code, and thanks beforehand.
PS: As you can see I echo some variables to see what's going on and the results are the ones I wrote before. THX.
Page 1 code:
<div id="divPago" class="content-container">
<form id ="formAgregarPago" method="POST" action= "<?php echo $agregarPagoURL; ?>" >
<input id="pagoNombre" name="pagoNombre" type="text" placeholder="Nombre">
<select id="pagoTipo" name="pagoTipo">
<option value = "Pago Evento">Pago Eventos</option>
<option value = "Pago Anual">Pago Anual</option>
<option value = "Pago Regular" hidden >Pago Regular</option>
</select>
<input id="pagoMonto" name= "pagoMonto" type="text" placeholder="Monto">
<button id="botonAgregarPago">Agregar</button>
<button id="botonCancelarPago">Cancelar</button>
</form>
Page 2 code:
if( isset($_POST['pagoNombre'] ) && isset($_POST['pagoTipo']) && isset($_POST['pagoMonto']) ){
global $wpdb;
$nombre =$_POST['pagoNombre'];
$tipo = $_POST['pagoTipo'];
$monto = $_POST['pagoMonto'];
$wpdb->show_errors();
$result = $wpdb->insert('pagos', array(
"id"=>"",
"nombre" => $nombre,
"tipo" => $tipo,
"monto" => $monto),
array("%d","%s", "%s", "%d"));
echo "<br>Error:".$wpdb->print_error();
echo "<br>Result:".$result;
echo "<br>Last Error:".$wpdb->last_error;
echo "<br>Var_DUMP:".var_dump($result);
echo "</div>";
}
else{
echo ("No llegan los datos !!!");
}
After reading the posts with similar problems with $wpdb->insert
I can't find the proper solution for my problem.
I have a template page where I send (via POST) the data to another template page to add rows to a custom table in wordpress database.
One of the values comes from a select, which one is received and processed unless it is not the last option of the select. So weird, I’ve enabled the wpdb->show_Errors()
and when the last option is selected it shows:
WordPress database error: [] SHOW FULL COLUMNS FROM `pagos`.
This only happens when I choose the last option of my select, I made it work adding an extra option in the last place and hiding it but is not a proper solution. Here is my code, and thanks beforehand.
PS: As you can see I echo some variables to see what's going on and the results are the ones I wrote before. THX.
Page 1 code:
<div id="divPago" class="content-container">
<form id ="formAgregarPago" method="POST" action= "<?php echo $agregarPagoURL; ?>" >
<input id="pagoNombre" name="pagoNombre" type="text" placeholder="Nombre">
<select id="pagoTipo" name="pagoTipo">
<option value = "Pago Evento">Pago Eventos</option>
<option value = "Pago Anual">Pago Anual</option>
<option value = "Pago Regular" hidden >Pago Regular</option>
</select>
<input id="pagoMonto" name= "pagoMonto" type="text" placeholder="Monto">
<button id="botonAgregarPago">Agregar</button>
<button id="botonCancelarPago">Cancelar</button>
</form>
Page 2 code:
if( isset($_POST['pagoNombre'] ) && isset($_POST['pagoTipo']) && isset($_POST['pagoMonto']) ){
global $wpdb;
$nombre =$_POST['pagoNombre'];
$tipo = $_POST['pagoTipo'];
$monto = $_POST['pagoMonto'];
$wpdb->show_errors();
$result = $wpdb->insert('pagos', array(
"id"=>"",
"nombre" => $nombre,
"tipo" => $tipo,
"monto" => $monto),
array("%d","%s", "%s", "%d"));
echo "<br>Error:".$wpdb->print_error();
echo "<br>Result:".$result;
echo "<br>Last Error:".$wpdb->last_error;
echo "<br>Var_DUMP:".var_dump($result);
echo "</div>";
}
else{
echo ("No llegan los datos !!!");
}
Share
Improve this question
edited Feb 17, 2020 at 0:47
Jacob Peattie
44.2k10 gold badges50 silver badges64 bronze badges
asked Feb 16, 2020 at 11:47
Ernesto AlonsoErnesto Alonso
12 bronze badges
4
|
1 Answer
Reset to default -1The ID can't be empty. If you have created your table and set your ID as auto increment, you don't have to insert it, it will be generated automatically.
So all you have to do is the following:
$result = $wpdb->insert('pagos', array(
"nombre" => $nombre,
"tipo" => $tipo,
"monto" => $monto),
array("%s", "%s", "%d"));
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744743297a4591157.html
hidden
on the last option? Does it work if you remove that? – Jacob Peattie Commented Feb 17, 2020 at 0:48tipo
? – Jacob Peattie Commented Feb 17, 2020 at 10:41