title: Why am I getting "network request failed" error?
body: <p>I'm trying to insert data into my MySQL database but I'm getting an error that says "Network request failed" on my simulator.  I'm guessing <code>fetch()</code>'s it has something to do with my systems IP address (even though I entered the right one).</p>
  
  <p>The <code>App.js</code> file is my React Native code. The <code>DBConfig.php</code> file identifies my database info. The <code>submit_user_info.php</code> file is responsible for populating the database and the <code>config.inc.php</code> (not included in this post because it's too long) file has my database configurations.</p>
  
  <p>Note: <code>config.inc.php</code> is found in MAMP > bin > phpMyAdmin > config.inc.php </p>
  
  <p>Note: In <code>DBConfig.php</code> I left <code>$HostUser</code> and <code>$HostPass</code> blank (<code>='')</code> because inside <code>config.inc.php</code>, on lines 568-569, both <code>$cfg['SQLValidator']['username']</code> and <code>$cfg['SQLValidator']['password']</code> are left blank.</p>
  
  <p><a href="https://i.stack.imgur.com/ed6YJ.png" rel="nofollow noreferrer">Error inside iOS simulator</a></p>
  
  <p>Here's <code>App.js</code>:</p>
  
  <pre><code>import React, { Component } from 'react';
  
  import { AppRegistry, StyleSheet, TextInput, View, Alert, Button } 
  from 'react-native';
  
  class ThisApp extends Component {
  
  constructor(props) {
  
      super(props)
  
      this.state = {
  
        TextInputName: '',
        TextInputEmail: '',
        TextInputPhoneNumber: ''
  
      }
  
    }
  
    InsertDataToServer = () =&gt;{
  
  
   const { TextInputName }  = this.state ;
   const { TextInputEmail }  = this.state ;
   const { TextInputPhoneNumber }  = this.state ;
  
  
  fetch('https://MySystemsIPAddress/submit_user_info.php', {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
  
      name: TextInputName,
  
      email: TextInputEmail,
  
      phone_number: TextInputPhoneNumber
  
    })
  
  }).then((response) =&gt; response.json())
        .then((responseJson) =&gt; {
  
  // Showing response message coming from server after inserting records.
          Alert.alert(responseJson);
  
        }).catch((error) =&gt; {
          console.error(error);
        });
  
  
    }
  
    render() {
      return (
  
  &lt;View style={styles.MainContainer}&gt;
  
          &lt;TextInput
  
            // Adding hint in Text Input using Place holder.
            placeholder="Enter Name"
  
            onChangeText={TextInputName =&gt; this.setState({TextInputName})}
  
            // Making the Under line Transparent.
            underlineColorAndroid='transparent'
  
            style={styles.TextInputStyleClass}
          /&gt;
  
          &lt;TextInput
  
            // Adding hint in Text Input using Place holder.
            placeholder="Enter Email"
  
            onChangeText={TextInputEmail =&gt; this.setState({TextInputEmail})}
  
            // Making the Under line Transparent.
            underlineColorAndroid='transparent'
  
            style={styles.TextInputStyleClass}
          /&gt;
  
          &lt;TextInput
  
            // Adding hint in Text Input using Place holder.
            placeholder="Enter Phone Number"
  
            onChangeText={TextInputPhoneNumber =&gt; this.setState({TextInputPhoneNumber})}
  
            // Making the Under line Transparent.
            underlineColorAndroid='transparent'
  
            style={styles.TextInputStyleClass}
          /&gt;
  
          &lt;Button title="Insert Text Input Data to Server" onPress={this.InsertDataToServer} color="#2196F3" /&gt;
  
  
  
  &lt;/View&gt;
  
      );
    }
  }
  
  const styles = StyleSheet.create({
  
  MainContainer :{
  
  justifyContent: 'center',
  flex:1,
  margin: 10
  },
  
  TextInputStyleClass: {
  
  textAlign: 'center',
  marginBottom: 7,
  height: 40,
  borderWidth: 1,
  // Set border Hex Color Code Here.
   borderColor: '#FF5722',
  
  // Set border Radius.
   //borderRadius: 10 ,
  }
  
  });
  
  export default ThisApp;
  </code></pre>
  
  <p>Here's <code>DBConfig.php</code></p>
  
  <pre><code>&lt;?php
  
  //Define your host here.
  $HostName = "localhost";
  
  //Define your database name here.
  $DatabaseName = "UserInfo";
  
  //Define your database username here.
  $HostUser = "";
  
  //Define your database password here.
  $HostPass = "";
  
  ?&gt;
  </code></pre>
  
  <p>Here's <code>submit_user_info.php</code>:</p>
  
  <pre><code>&lt;?php
  
  // Importing DBConfig.php file.
  include 'DBConfig.php';
  
  // Creating connection.
   $con = mysqli_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 name from JSON $obj array and store into $name.
  $name = $obj['name'];
  
  // Populate email from JSON $obj array and store into $email.
  $email = $obj['email'];
  
  // Populate phone number from JSON $obj array and store into $phone_number.
  $phone_number = $obj['phone_number'];
  
   // Creating SQL query and insert the record into MySQL database table.
  $Sql_Query = "insert into UserInfoTable (name,email,phone_number) values ('$name','$email','$phone_number')";
  
  
   if(mysqli_query($con,$Sql_Query)){
  
   // If the record inserted successfully then show the message.
  $MSG = 'Data Inserted Successfully into MySQL Database' ;
  
  // Converting the message into JSON format.
  $json = json_encode($MSG);
  
  // Echo the message.
   echo $json ;
  
   }
   else{
  
   echo 'Try Again';
  
   }
   mysqli_close($con);
  ?&gt;
  </code></pre>