Itβs very difficult for me to understand how all this works. I spent several days with this and could not come up with any results. I am trying to fill in a text box on a form, and when the form is submitted, I want to add text to my sqlite db using ajax.
I understand that you need a call to $ .get in jquery, which runs in the submit form. This is similar to the fact that I can run js-boxes. However, when I pass in the address of a php script that has lines to add to sqlite db using PDO, nothing is added to db. However, when I run this PHP script using php cli, something will be added to db.
It seems to me that there is no significant step. I would really appreciate if someone could bridge this gap for me!
Edit: At Martin's request, there is a code here:
My php generates a list like this with a form in the middle:
<ul> <li>hello</li> <li id="formItem"> <form action="" method="post"> <input type=text name="content"/> </form> </li> <li>world</li> </ul>
Then my jquery code looks like to add everything that is in the text box directly above it, ajax is called in the list. This is inside $ (document) .ready (function () {.
$("form").submit(function() { var inputText = $("input").val(); $.ajax({ type: "POST", url: "add.php", data: inputText, success: function() { $('#formItem').prev().after( "<li>" + inputText + "</li>" )} }); });
My add.php file looks like this and it will insert something into my db if I run the php script in cli:
<?php $base = new PDO('sqlite:todo.db'); $sql = $base->prepare("INSERT INTO ThisTable (content, priority) VALUES ('lolololol', 1);"); $sql->execute(); $base = null; ?>