close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Insert error

Thread began 1/23/2020 7:28 am by María Luisa | Last modified 1/23/2020 1:20 pm by Ray Borduin | 56 views | 6 replies |

María Luisa

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?

Sign in to reply to this post

Ray BorduinWebAssist

Have you re-installed recently to get the latest version of queryobj.php? I'm thinking there may be an issue in your version causing the problem. I've attached the latest version, please try replacing it and see if that corrects the problem. If it does, then try reinstalling either Data Bridge or MySQLi Server Behaviors to make sure the latest version is used in future applications.

Attached Files
queryobj.php
Sign in to reply to this post
Did this help? Tips are appreciated...

María Luisa

The problem continues

Thanks Ray, as always, for your kindness.

I have replaced the queryobj.php that indicates the one I had installed. But the problem continues when I try to insert from the first radio button: I click on it and when I click the submit button, this error appears:
----
( ! ) Warning: Wrong parameter count for mysqli_stmt::bind_param() in /Applications/MAMP/htdocs/CST_Fluidos_01/webassist/mysqli/queryobj.php on line 494
Call Stack
# Time Memory Function Location
1 0.0014 365720 {main}( ) .../Prueba_input2.php:0
2 0.0093 541544 WA_MySQLi_Query->execute( ) .../Prueba_input2.php:25
3 0.0097 541952 bind_param ( ) .../queryobj.php:494
There is an error in your SQL syntax.
----

In the case of queryobj.php that previously indicated on line 466 now reference it in 494.

I do not know what I did wrong

Sign in to reply to this post

Ray BorduinWebAssist

You have:

$InsertQuery->bindColumn("modalidad2", "s", "".($modalidadE) ."", "WA_DEFAULT");

Most likely that column doesn't have a default value, so you would need something like:

$InsertQuery->bindColumn("modalidad2", "s", "".($modalidadE) ."", "WA_BLANK");

The other issue is that you must not be getting a value set for $modalidadE. This happens because you have the attribute: readonly="readonly"

When a field is set to readonly it isn't actually submitted with the form. To fix that you could probably use:

php:
<?php

$modalidadE
"Este texto será siempre el mismo";
if(isset(
$_POST['modalidadE'])){
$modalidadE$_POST['modalidadE'];} ?>



instead of what you have now:

php:
<?php

if(isset($_POST['modalidadE'])){
$modalidadE$_POST['modalidadE'];} ?>
Sign in to reply to this post
Did this help? Tips are appreciated...

María Luisa

Some things are solved

Thanks a lot again Ray.

With these changes that you proposed to me the error no longer occurs when I insert the text corresponding to the first radio button but, nevertheless, nothing is inserted in the database in the corresponding column although something happens in the insertion because it generates an id in the corresponding column of that table.

It occurred to me to remove the readonly attribute from the text field, but the same thing happens: do not write anything in the table when inserting.

In the case of the second button, it continues to work perfectly

Sign in to reply to this post

Ray BorduinWebAssist

I think I see why. Try using:

php:
<?php

$modalidadE
"Este texto será siempre el mismo";
if(isset(
$_POST['modalidadE']) && $_POSt["radioMod"] !== "0"){
$modalidadE$_POST['modalidadE'];} ?>



insead of:

php:
<?php

$modalidadE
"Este texto será siempre el mismo";
if(isset(
$_POST['modalidadE'])){
$modalidadE$_POST['modalidadE'];} ?>
Sign in to reply to this post
Did this help? Tips are appreciated...

María Luisa

Solved!! :)

Ohhh, Ray, thanks a million. How fine, it was necessary to add the condition that the value of the radio button was 0.

It is perfectly solved.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...