admin管理员组文章数量:1391943
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"));
本文标签: databasewpdbgtinsert not working for last select option
版权声明:本文标题:database - $wpdb->insert not working for last select option 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744743296a2622738.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