Home>

As the title says.

The PHP file is on the Sakura server and the data is sent to the DB of that server. IOS can send and save the data, but only Android can.

Android has tried both real and emulators, but it's a bad situation.

I don't think there is a pinpoint solution, so please let me know if you can think of it.
Thank you.

// MemoDataCreateScreen.js
 class MemoDataCreateScreen extends React.Component {
  state = {
    text: '',
    mean: ''
  };
  addSQL () {
    if (this.state.text == ''&&this.state.mean == '')
      return Alert.alert ('Not entered');
    const request = new XMLHttpRequest ();
    request.onreadystatechange = function () {
      console.log (request);
      if (request.readyState === 4) {
        if (request.status == 200) {
          console.log ('communication successful');
        } else {
          console.log ('communication failure');
        }
      }
    };
    request.onload = function () {
      console.log ('Communication complete!');
    };
    request.open (
      'POST',
      'https: // server name here/secret.php',
      true
    );
    request.send (`text = ${this.state.text}&mean = ${this.state.mean}`);
  }
  test () {
    console.log ('test');
  }
  render () {
    return (
      <View>
        <TextInput
          style = {styles.textInput}
          placeholder = 'Enter text here'
          onChangeText = {text =>{
            this.setState ({
              text: text
            });
          }}
        ></TextInput>
        <TextInput
          style = {styles.textInput}
          placeholder = 'Enter Mean here'
          multiline
          onChangeText = {text =>{
            this.setState ({
              mean: text
            });
          }}
        ></TextInput>
        <TouchableHighlight>
          <Button title = 'Send' onPress = {() =>this.addSQL ()} />
        </TouchableHighlight>
      </View>
    );
  }
}
// secret.php
<? php
$textValue = $_POST ["text"];
$mean = $_POST ["mean"];
echo 'test';
try {
    $pdo = new PDO ('mysql: dbname = ksk-tennis_english;charset = utf8;host = mysql743.db.sakura.ne.jp', 'ksk-tennis', 'yukitiindb11');// The first root is id , The second is the password
} catch (PDOException $e) {
    exit ('DB Error:'. $e->getMessage ());
}

// 3. Create data registration SQL
$sql = "INSERT INTO` posts` (`indate`,` text`, `mean`) VALUES (sysdate () ,: textValue,: mean)";
$stmt = $pdo->prepare ($sql);
$stmt->bindValue (': textValue', $textValue, PDO :: PARAM_STR);// Integer (PDO :: PARAM_INT for numbers)
$stmt->bindValue (': mean', $mean, PDO :: PARAM_STR);// Integer (PDO :: PARAM_INT for numeric values)
$status = $stmt->execute ();// execute
// var_dump ("aaa");
// debag like
// 4. After data registration process
if ($status == false) {
    // If there is an error during SQL execution (get error object and display)
    $error = $stmt->errorInfo ();
    exit ("SQL Error:". $error [2]);
} else {
    // 5. Redirect to index.php
    echo "sent";
    // header ("Location: index.php");
    exit ();// The exit is not a magic
}
// AndroidManifest.xml
<manifest xmlns: android = "http://schemas.android.com/apk/res/android"
  package = "com.helloworld">
    <uses-permission android: name = "android.permission.INTERNET" />
    <uses-permission android: name = "android.permission.RECORD_AUDIO" />
    
      
        <intent-filter>
            
            <category android: name = "android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      
    </application>
</manifest>
  • Answer # 1

    After a qs.post with axios, I was able to go normally, so after a thorough review of the code,

    request.setRequestHeader (
          'Content-Type',
          'application/x-www-form-urlencoded'
        );
    request.send (`text = ${this.state.text}&mean = ${this.state.mean}`);

    Four lines were added to the last .send in addSQL.
    It seems to specify the type to send, but it seems that the way to write in send does not work unless you do this type. It was a bit difficult, so in this case I moved like this. Thank you for feeling.