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 !!!");
}
hidden
on the last option? Does it work if you remove that?tipo
?