Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>.html file</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $("#check").click(function(){ $("#keyvalue").text($("#key").val()); }); $("#submit").click(function(){ var text = $("#text").val(); var key = $("#key").val(); $.ajax({ url: 'trial.php', data: {text: text, key:key}, type: 'POST', dataType: 'json', success: function(data) { if(data.status == "fail"){ $("#status").html(data.message); }else{ $("#status").html(data.message); $("#key").val(data.key); $("#keyvalue").text(''); } } }); return false; }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form method="post" action="trial.php" onsubmit="return send_form();"&gt; &lt;input type="text" name="text" id="text"/&gt; &lt;input type="hidden" id="key" name="key" value="xsaigoehf7118191"/&gt; &lt;button id="submit"&gt;Send data and get new key&lt;/button&gt; &lt;/form&gt; &lt;br&gt;&lt;br&gt; &lt;div id="status"&gt;&lt;/div&gt; &lt;br&gt;&lt;br&gt; &lt;button id="check"&gt;What's current value of key?&lt;/button&gt; --------&gt; &lt;span id="keyvalue"&gt;&lt;/span&gt; &lt;div id="response"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>.php</p> <pre><code>&lt;?php //You get the form contents here. $key = isset($_POST['key']) ? $_POST['key'] : "error"; $text = isset($_POST['text']) ? $_POST['text'] : "empty"; //Check them if it matches with DB's entry, if doesn't you set $key = "error"; if($key=="error"){ $status = "fail"; $message = "There was some error processing your form."; exit; } else{ //You generate another random key. $random =''; for ($i = 0; $i &lt; 10; $i++) { $random .= chr(mt_rand(33, 126)); } //Now here in steps save it to your DB. So that when next form is submitted you can match it. //And send back response to html file, where ajax will refresh the key. $status = "success"; $message = " Your form was processed succesfully&lt;br&gt; The text you sent was ".$text.", and the key you sent was ".$key.". The new key sent to you can be seen by pressing the button below, has value, ".$random."&lt;br&gt;&lt;br&gt; "; } echo json_encode(array("status" =&gt; $status, "message" =&gt; $message, "key" =&gt; $random)); ?&gt; </code></pre> <p>Hope this helps you.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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