Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It should be like</p> <p>Your <strong>HTML Page</strong></p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;script&gt; function checkIfUserCanBeSaved(){ var userRegData = $('#registration').serialize(); $.ajax({ type: 'POST', data: userRegData, url: 'http://www.somedomain.com/php/userregistration.php', success: function(data){ if(response==1){ alert('user found'); } else { alert('user saved') } }, error: function(e){ console.log('There was an error'); $.mobile.loading ('hide'); } }); return false; } &lt;/script&gt; &lt;form id="registration"&gt; &lt;input type="text" name="username"&gt; &lt;input type="text" name="password"&gt; &lt;input type="button" onclick="checkIfUserCanBeSaved()" value="submit"&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Your <strong>PHP Page</strong></p> <pre><code>$db = new PDO('mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']['dbname'], $config['db']['username'], $config['db']['password']); $db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $username = $_POST['username']; $password = $_POST['password']; try { $db-&gt;beginTransaction(); try { $query = $db-&gt;prepare("SELECT user.Username FROM user WHERE user.Username = :username LIMIT 1"); $query-&gt;bindValue(':username', $username, PDO::PARAM_STR); $query-&gt;execute(); if ( $query-&gt;rowCount() &gt; 0 ) { $response=1; echo $response; } else { $response=0; $query = $db-&gt;prepare("INSERT INTO user ( username, password ) VALUES ( :username, :password )" ); $query-&gt;bindValue(':username', $username, PDO::PARAM_STR); $query-&gt;bindValue(':password', $password, PDO::PARAM_STR); $query-&gt;execute(); echo $response; $db-&gt;commit(); } } catch (PDOException $e) { die ($e-&gt;getMessage()); } } catch (PDOException $e) { $db-&gt;rollBack(); die ($e-&gt;getMessage()); } </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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