2

When i try to run php code using Parse.com PHP SDK it the error is "Account already exists for this username"

but it throw all this error message:

Fatal error: Uncaught exception 'Parse\ParseException' with message 'Account already exists for this username' in /Users/yousef/Desktop/project/vendor/parse/php-sdk/src/Parse/ParseClient.php:357 Stack trace: #0 /Users/yousef/Desktop/project/vendor/parse/php-sdk/src/Parse/ParseObject.php(1038): Parse\ParseClient::_request('POST', 'classes/_User', NULL, '{"username":"my...', false) #1 /Users/yousef/Desktop/project/vendor/parse/php-sdk/src/Parse/ParseObject.php(947): Parse\ParseObject::deepSave(Object(Parse\ParseUser), false) #2 /Users/yousef/Desktop/project/vendor/parse/php-sdk/src/Parse/ParseUser.php(108): Parse\ParseObject->save() #3 /Users/yousef/Desktop/project/test.php(20): Parse\ParseUser->signUp() #4 {main} thrown in /Users/yousef/Desktop/project/vendor/parse/php-sdk/src/Parse/ParseClient.php on line 357

The Code i Use

<?php

require 'vendor/autoload.php';

use Parse\ParseClient;

ParseClient::initialize('YousefId', '', 'YousefMaster');
ParseClient::setServerURL('server-ip:1337/parse');


use Parse\ParseUser;

$user = new ParseUser();
$user->set("username", "my name");
$user->set("password", "my pass");
$user->set("email", "[email protected]");
$user->set("phone", "415-392-0202");

try {
  $user->signUp();
} catch (ParseException $error) {
    echo $error->getCode();
    echo $error->getMessage();
}

?>

so how do i just show the error code and message instead of showing all this error.

1 Answer 1

2

You need to refer to the ParseException within the Parse namespace.

Try

catch (Parse\ParseException $error) {
    // ...
}
Sign up to request clarification or add additional context in comments.

5 Comments

Still the same issue, and i don't think this is the issue because on Github the Parse PHP SDK using it as i did.
oh, sorry it worked i typed it wrong in my code, so yea ur code is working fine which made me wonder why on github say's different.
Probably the documentation is slightly out of date. Maybe you can submit a pull request to fix it!
I had a look at the documentation and they don't specifically mention namespacing. An alternate fix which would replicate the code they have in their documentation would be to add a namespace definition of namespace Parse at the top of the file.
user Parse where exactly ? u mean instead of use Parse/ParseClient ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.