Insert error
Hi
I have a simple form: two radio buttons, a text field and a text area.
The idea is that when the user clicks the radio button id moda1, the read-only text field modalidadE (id fijo) becomes available for the insert.
If, on the other hand, you click on the radio button id moda2, the previous field is disabled and the user can enter the text in the text area (id tcontenidoMod).
The corresponding column in the database is always the same: modalidad2. The name of the text field and the text area is ModalidadE.
Here my code.
---
<?php require_once('../webassist/mysqli/queryobj.php'); ?>
<?php require_once('../Connections/conexion.php'); ?>
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>PRUPRU</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<?php
if(isset($_POST['modalidadE'])){
$modalidadE= $_POST['modalidadE'];} ?>
<?php
if (isset($_POST["enviar"]) || isset($_POST["enviar_x"])) {
$InsertQuery = new WA_MySQLi_Query($conexion);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "modensayo2";
$InsertQuery->bindColumn("modalidad2", "s", "".($modalidadE) ."", "WA_DEFAULT");
$InsertQuery->saveInSession("insertado");
$InsertQuery->execute();
$InsertGoTo = "";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
$InsertQuery->redirect($InsertGoTo);
}
?>
</head>
<body>
<form action="" method="post" name="formulario" id="formulario">
<table>
<tr>
<td>
<input type="radio" name="radioMod" id="moda1" value="0" checked>
</td>
<td><input name="modalidadE" type="text" class="form-control" id="fijo" value="Este texto será siempre el mismo" size="60" readonly="readonly">
</td>
</tr>
<tr>
<td>
<input type="radio" name="radioMod" id="moda2" value="1">
</td>
<td><textarea name="modalidadE" cols="60" rows="3" class="form-control" id="tcontenidoMod" placeholder="Escriba aquí su texto para Modalidad de Ensayo"></textarea>
</td>
</tr>
<tr>
<td></td>
<td>
<input name="enviar" type="submit" value="Enviar">
</td>
</tr>
</table>
</form>
<script>
$(document).ready(function(){
$("input[name='radioMod']").change(function(){
if($(this).val()==1){
$("#fijo").attr("disabled",true);
$("#tcontenidoMod").removeAttr("disabled");
} else{
$("#tcontenidoMod").attr("disabled",true);
$("#fijo").removeAttr("disabled");
}
});
});
</script>
</body>
</html>
---
If I insert with the radio button id moda2, the text inserted in the text area is written to the database correctly. But if I click on the first radio button to insert the default text of the text field into the database first, it gives me a series of errors that I copy below.
---
( ! ) Warning: Wrong parameter count for mysqli_stmt::bind_param() in /Applications/MAMP/htdocs/CST_Fluidos_01/webassist/mysqli/queryobj.php on line 466
Call Stack
# Time Memory Function Location
1 0.0015 365720 {main}( ) .../Prueba_input2.php:0
2 0.0189 530296 WA_MySQLi_Query->execute( ) .../Prueba_input2.php:25
3 0.0192 530704 bind_param ( ) .../queryobj.php:466
There is an error in your SQL syntax.
---
The line 25 in my code is: $InsertQuery->execute();
I do not know what I'm doing wrong. Can someone help me please?