Login not successful on ionic

How to create an alert box that login credential is wrong after being passed through to php.

was thinking of using an alert box and display the result but i got Unexpected token N in JSON at position etc etc.

if i set regular alert - saying enter correct credential and dismissed that alert in a few sec…that’s not working

if i don’t put anything …then it will just return the user_id undefined which is correct for the php validation.

is this ionic 1 or ionic 2/3? you can probably search in google with lots of tutorials out there… for example this one https://devdactic.com/simple-login-example-with-ionic-and-angularjs/ which I prefer really good tutorial which explains everything thoroughly…

I saw that tutorial… I already set jsonencode on my php for the wrong username… And the console log error returned the wrong username. That’s good.

But how I am not sure how to pass that on to the alert box.

maybe you should try this

$scope.showAlert = function() {
   var alertPopup = $ionicPopup.alert({
     title: 'Login!',
     template:  $scope.username  + 'is incorrect'

   alertPopup.then(function(res) {

My ionic version is 3.9.2

My php is like this

If username existed… Then pass the userdata.jsonencode to the app and let the user pass on to the next page. (Works fine)
$noresult = 0
$returnerror = jsonencode($noresult);
Echo $returnerror <-- console log returns the username that was inserted…

and I’m thinking I can get that $returnerror value… And my .ts file can capture that value and then do
If value = 0 then popup alert appear.

Why do I get the feeling I’m over thinking this while the answer is simple

you should change the topic to ionic from ionic-v1 so that others can check about what your problem is…

yep . changed that.

basically i’m trying to not show the runtime error page…and change it to popup box if possible.

edit: i think i’ll use presentToast instead of the alertbox.


edited the code to :

(err) => { console.log(err); this.presentToast(err); }

and php error :

else { echo '{"error":{"Bad request wrong username and password"}}'; } <-- console log returned this correctly.

never mind… i got it working finally :smiley: