Note that there are some explanatory texts on larger screens.

plurals
  1. POIf input empty, no insert in mysql (pdo)
    primarykey
    data
    text
    <p>If any of input fields is blank, then do not insert in mysql. It is possible (acceptable) that some of input fields are blank. In such case I need to insert non blank fields (values). But the script does not insert at all.</p> <p>I can write something like </p> <pre><code>if ( (strlen($date_day1) &lt; 1) ) { $date_day1 = 0; } </code></pre> <p>But may be better solution? If empty input field, insert all other fields. Empty field may not insert or inser 0.</p> <p>Input</p> <pre><code>&lt;input type="text" name="date_day1" id="date_day1"&lt;/td&gt; &lt;input type="text" name="amount1" id="amount1"&lt;/td&gt; &lt;input type="text" name="row_id1" id="row_id1"&lt;/td&gt; </code></pre> <p>Then ajax get input values</p> <pre><code>$(document).ready(function(){ autosave(); }); function autosave() { var t = setTimeout("autosave()", 5000); var date_day1 = $("#date_day1").val(); var amount1 = $("#amount1").val(); var row_id1 = $("#row_id1").val(); $.ajax( { type: "POST", url: "_autosave.php", data: "date_day1=" + date_day1 + "&amp;amount1=" + amount1+ "&amp;row_id1=" + row_id1, cache: false, } ); } </code></pre> <p>Then php get variables</p> <pre><code>$date_day1 = $_POST['date_day1']; $amount1 = $_POST['amount1']; $row_id1 = $_POST['row_id1']; </code></pre> <p>And then try to record in mysql</p> <pre><code>$stmt_insert = $db-&gt;prepare("INSERT INTO 2_1_journal(RecordDay, Amount, RowId) VALUES(:RecordDay,:Amount,:RowId)"); $stmt_insert-&gt;execute(array(':RecordDay' =&gt; $date_day1, ':Amount' =&gt; $amount1, ':RowId' =&gt; $row_id1, </code></pre> <p>));</p> <p><strong>Update</strong></p> <p>With such changed ajax insert works, but this does not work <code>success: function(){ document.getElementById('is_row_changed1').value = 0;}</code></p> <pre><code>$(document).ready(function(){ autosave(); }); function autosave() { var t = setTimeout("autosave()", 5000); var date_day1 = $("#date_day1").val(); var amount1 = $("#amount1").val(); var row_id1 = $("#row_id1").val(); if ($("#is_row_changed1").val() &gt; 0) { $.ajax( { type: "POST", url: "_autosave.php", dataType: "json", data: {"date_day1" : date_day1, "amount1" : amount1, "row_id1" : row_id1}, cache: false, success: function(){ document.getElementById('is_row_changed1').value = 0; } } ); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload