Note that there are some explanatory texts on larger screens.

plurals
  1. POCheck if user exists
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/14024815/phonegap-load-values-from-database-based-on-a-user-id">Phonegap - Load Values from Database based on a user ID</a> </p> </blockquote> <p>I am creating a Phonegap application that requires user registration. I am doing this through a PHP Script acting as a web service to a MySQL database and using the AJAX POST/Get method.</p> <p>For some reason LogCat is always giving me <code>"There was an error"</code> (falls in the error function of the post) . </p> <p><strong>UPDATED:</strong> From the logs of MySQL I am getting this error:<br> PHP Fatal error: Call to a member function <code>bindValue()</code> on a non-object <br> It points to this line: <code>$username = $_POST['username']</code>;</p> <p>Here is a snippet of my JS code:</p> <pre><code>var u = $("#username").val(); var p = $("#password").val(); var userRegData = $('#registration').serialize(); $.ajax({ type: 'POST', data: userRegData, dataType: 'JSONp', url: 'http://www.somedomain.com/php/userregistration.php', success: function(data){ if(response==1){ // User can be saved } else { // User exsts already } }, error: function(e){ console.log('There was an error'); $.mobile.loading ('hide'); } }); return false; </code></pre> <p>And here is a snippet of my PHP code. I am using PDO.</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']; $query-&gt;bindValue(':username', $username, PDO::PARAM_STR); $query-&gt;bindValue(':password', $password, PDO::PARAM_STR); try { $db-&gt;beginTransaction(); $db-&gt;query("SELECT `user`.`Username` FROM `user` WHERE `user`.`Username` = :username LIMIT 1"); try { if ( $query-&gt;rowCount() &gt; 0 ) { $response=1; echo $response; } else { $response=0; $db-&gt;query("INSERT INTO `user` (`user`.`Username`, `user`.`Password`) VALUES :username, :password"); 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.
 

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