Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9040641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:02:33+00:00 2026-06-16T10:02:33+00:00

Possible Duplicate: Phonegap – Load Values from Database based on a user ID I

  • 0

Possible Duplicate:
Phonegap – Load Values from Database based on a user ID

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.

For some reason LogCat is always giving me "There was an error" (falls in the error function of the post) .

UPDATED:
From the logs of MySQL I am getting this error:
PHP Fatal error: Call to a member function bindValue() on a non-object
It points to this line: $username = $_POST['username'];

Here is a snippet of my JS 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;

And here is a snippet of my PHP code. I am using PDO.

$db = new PDO('mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']['dbname'], $config['db']['username'], $config['db']['password']);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$username = $_POST['username'];
$password = $_POST['password'];
$query->bindValue(':username', $username, PDO::PARAM_STR);
$query->bindValue(':password', $password, PDO::PARAM_STR);

try {

$db->beginTransaction();

$db->query("SELECT `user`.`Username` FROM `user` WHERE `user`.`Username` = :username LIMIT 1");
try {
    if ( $query->rowCount() > 0 ) {
        $response=1;
        echo $response;
    }
    else {
        $response=0;
        $db->query("INSERT INTO `user` (`user`.`Username`, `user`.`Password`) VALUES :username, :password");
        echo $response; 
        $db->commit();  
    }
} catch (PDOException $e) {
    die ($e->getMessage());
}


} catch (PDOException $e) {
    $db->rollBack();
    die ($e->getMessage());
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:02:34+00:00Added an answer on June 16, 2026 at 10:02 am

    It should be like

    Your HTML Page

    <html>
        <body>
            <script>
                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;
                }
            </script>
            <form id="registration">
                <input type="text" name="username">
                <input type="text" name="password">
                <input type="button" onclick="checkIfUserCanBeSaved()" value="submit">
            </form>
        </body>
    </html>
    

    Your PHP Page

    $db = new PDO('mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']['dbname'], $config['db']['username'], $config['db']['password']);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    $username = $_POST['username'];
    $password = $_POST['password'];
    
    
    try {
    
    $db->beginTransaction();
    
    try {
    
         $query = $db->prepare("SELECT user.Username FROM user WHERE user.Username = :username LIMIT 1");
         $query->bindValue(':username', $username, PDO::PARAM_STR);
         $query->execute();
    
        if ( $query->rowCount() > 0 ) {
            $response=1;
            echo $response;
        }
        else {
            $response=0;
            $query = $db->prepare("INSERT INTO user ( username, password ) VALUES ( :username, :password )" );
            $query->bindValue(':username', $username, PDO::PARAM_STR);
            $query->bindValue(':password', $password, PDO::PARAM_STR);
            $query->execute();
            echo $response; 
            $db->commit();  
        }
    } catch (PDOException $e) {
        die ($e->getMessage());
    }
    
    
    } catch (PDOException $e) {
        $db->rollBack();
        die ($e->getMessage());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: phonegap - splash screen for Android app I have an application built
Possible Duplicate: Can’t create handler inside thread that has not called Looper.prepare() inside AsyncTask
Possible Duplicate: get current latitude and longitude from gps enabled device I use the
Possible Duplicate: How to use Google Analytics with Phonegap without a plugin? I want
Possible Duplicate: Filetype association with application (C#) I'm writing a C# Windows app to
Possible Duplicate: When do you use the “this” keyword? Hello, I understand that the
Possible Duplicate: What to do when I want to use database constraints but only
Possible Duplicate: Generic methods and multiple constraints I need a generic function that has
Possible Duplicate: Horizontally scrollable image on Android + PhoneGap + jQuery Mobile how to
Possible Duplicate: Understanding NSRunLoop Till now I know that every thread has its own

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.