0

Everyone i'm Using odoo12 site web with database postgresql and I Create an app Using react-native , and i want to connect my app with postgresql database by The way The Database is separated in another server wher i'm working Could you help me Please ? I'm Waiting For your Response

best regards eyounes

Everyone
i'm Using odoo12 site web with database postgresql
and I Create an app Using react-native , and i want to connect my app with 
postgresql database
by The way The Database is separated in another server wher i'm working
Could you help me Please ?
I'm Waiting For your Response

best regards
eyounes

/*************** Login Code ************/
UserLoginFunction = () =>{

const { username }  = this.state ;
const { password }  = this.state ;
fetch('http://192.168.43.56/ff/users.php', {
      method: 'POST',
      headers: {
         'Accept': 'application/json',
         'Content-Type': 'application/json',
       },
       body: JSON.stringify({

        username: username,

         password: password

       })

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

             // If server response message same as Data Matched
            if(responseJson === 'Data Matched')
             {enter code here

                 //Then open Profile activity and send user email to profile activity.
                 this.props.navigation.navigate('intervention', { Email: UserEmail });

             }
             else{

               Alert.alert(responseJson);
             }

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

       } 

    /********************** DbConfig.php *********************/

 <?php

  //Define your host here.
  $HostName = "Odoo-serv12";

  //Define your database name here.
  $DatabaseName = "Lpn_auto";

  //Define your database username here.
  $HostUser = "openpg";

  //Define your database password here.
  $HostPass = "openpg";

  ?>
/******************* users.php *****************/
<?php

 // Importing DBConfig.php file.
 include 'DBConfig.php';

 // Creating connection.
  $con = pg_connect($HostName,$HostUser,$HostPass,$DatabaseName);

  // Getting the received JSON into $json variable.
  $json = file_get_contents('php://input');

  // decoding the received JSON and store into $obj variable.
  $obj = json_decode($json,true);

 // Populate User email from JSON $obj array and store into $email.
 $username = $obj['login'];

 // Populate Password from JSON $obj array and store into $password.
 $password = $obj['password'];

 //Applying User Login query with email and password match.
 $Sql_Query = "select * from res_users where login = '$username' and password = '$password' ";

 // Executing SQL Query.
 $check = pg_fetch_array(pg_query($con,$Sql_Query));


 if(isset($check)){

  $SuccessLoginMsg = 'Data Matched';

  // Converting the message into JSON format.
 $SuccessLoginJson = json_encode($SuccessLoginMsg);

 // Echo the message.
  echo $SuccessLoginJson ; 

  }

  else{

  // If the record inserted successfully then show the message.
 $InvalidMSG = 'Invalid Username or Password Please Try Again' ;

 // Converting the message into JSON format.
 $InvalidMSGJSon = json_encode($InvalidMSG);

 // Echo the message.
  echo $InvalidMSGJSon ;

  }

pg_close($con);
 ?>

Here is all Derails About Thank you

This The ERROR I have

younes
  • 11
  • 2
  • Does your server have API endpoints set up? Your client application doesn't access the database directly, you need to query the server with http requests. The server should handle processing the requests and returning data. – Cal Irvine May 31 '19 at 13:37
  • it's an Local Server ,I Try to Conncet to database using This Php Code but it Doesn't Work , – younes May 31 '19 at 13:53
  • 1
    Please add the code that you are trying to make work to your question. This site is meant for specific questions. If you show as your work we can help. As it is, there is not enough to go on. – Cal Irvine May 31 '19 at 14:02
  • I add The Code on Question Sir , Thank you – younes May 31 '19 at 14:08
  • What response are you getting from the server? – Cal Irvine May 31 '19 at 14:14
  • I add The ScreenShoot On my Question For The Error , Thank you – younes May 31 '19 at 14:41
  • I'm not sure what the issue is based on the errors you are getting. A good place to start is probably CORS headers https://stackoverflow.com/questions/8719276/cors-with-php-headers Sorry I can't be more help than that. – Cal Irvine May 31 '19 at 16:21

0 Answers0