Note that there are some explanatory texts on larger screens.

plurals
  1. POajax call to check duplicate data
    primarykey
    data
    text
    <p>Here is the form to have ajax check out user existence.</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt;&lt;title&gt;Register new user!&lt;/title&gt; &lt;script src="jquery-1.7.1.min.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; Username: &lt;input type="text" name="username" id="username"/&gt;&lt;span id="user"&gt;&lt;/span&gt;&lt;br/&gt; Password: &lt;input type="password" name="password" id="password"/&gt;&lt;br/&gt; &lt;input type="button" value="Register" name="submit" id="submit" onclick="register_user();"/&gt; &lt;/body&gt; &lt;script&gt; function register_user() { $.ajax( { type:"POST", data:username, url:"userexists.php" }) .fail(function() { $('#user').html("This user already exists"); } ); } &lt;/script&gt; &lt;/html&gt; </code></pre> <p>And here is the userexists.php module</p> <pre><code>&lt;?php // connection to the db define(IPHOST,"localhost"); define(DBPASSWORD,""); define(DBUSER,"root"); define(DATABASE,"ajaxtest"); define(TABLENAME,"at"); $conn=mysql_connect(IPHOST,DBUSER,DBPASSWORD) or die(mysql_error()); mysql_select_db(DATABASE) or die(mysql_error()); $username=$_POST('username'); $sql="SELECT username FROM ".TABLENAME." WHERE username=".$username; $query=mysql_query($sql); if(0!=mysql_numrows($query)) { // } else { } ?&gt; </code></pre> <p>But I am stuck to really figure out how the ajax function actually works, what should I enter the blank field after I know that the entered username has been used, for example ? I don't understand ajax at all.</p> <p>[<strong>UPDATE</strong>] Thank you, I understand it now, I have got several answers, don't know which one to choose as the best reply. No option to choose all.</p>
    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