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());
}
It should be like
Your HTML Page
Your PHP Page