简体   繁体   中英

PHP Webhost Operation Checking

I wanted perform checking if the PHP Webhost is complete whenever perform a update function, if everything doing fine then send an notification and let the Application know the Operation is Doing fine.

Basically I wanted to know if the query in PHP work and use my application to notify the user.

is there any way or method to do so?

I using this method to fetch data from PHP in my React Native App

RecipeUpdation = () =>{
   const { ID }  = this.state ;
   const { Name }  = this.state ;
   const { Type }  = this.state ;
   const { Ingredient }  = this.state ;
   const { Step } = this.state ;

   return fetch('https://www.update.php', {
       method: 'POST',
       headers: {
         'Accept': 'application/json',
         'Content-Type': 'application/json',
       },
       body: JSON.stringify({

         RecipeID : ID,
       RecipeName : Name,
       RecipeType : Type,
       RecipeIngredient: Ingredient,
       RecipeStep: Step

       })

     }).then((response) => response.json())
           .then((responseJson) => {
           }).catch((error) => {
             console.error(error);
           });

       }

Basically we can verify if the Operation in PHP is successful or not by Checking the Query Execution Status. A very Basic way to do the checking is using If Else to see if the Query Function return True (Success) or False (Fail). You can also always return some Message through JsonResponds .

Here some example Code for PHP checking and Return Some Message:

// Using If Else to Check if operation Success or Not
if(mysqli_query($connection,$Your_Query)){

$MSG = 'Success' ;

// Convert message into Json format first
$json = json_encode($MSG);

// This is where it return the message to Application.
 echo $json ;

 }
 else{

 $MSG = 'Failed' ;

 $json = json_encode($MSG);

 echo $json ;
 }

In your Application Code you already have the implementation to retrieve the JsonResponds (the Message) which have been echo in the PHP Code, I would suggest use a simple method which is Alert to pop out the message in your React Native Application to notify the User the Operation Status.

 }).then((response) => response.json())
       .then((responseJson) => {

         // this responseJson Already have the echo Message from PHP
         // just Display the Status with Alert Function
         Alert.alert(responseJson);

       }).catch((error) => {
         console.error(error);
       });

Hope this would help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM