react native connect with mysql php
Tutorial 0 Commentsreact native connect with mysql php, show toast show output in variable check
Get = user detail fetch
post= user data add, sign up
put, patch= used for update data
put= old data completle change karna, all user data update like username, email, phone, password
delete= used for delete user data
patch = just single or some user detail update so used like= onliny email, password
PHP mysql jason file download check
jassion file download on click
jason file in php
/** * Sample React Native App * https://github.com/facebook/react-native * * @format * @flow strict-local */ import * as React from 'react'; import{ View, TextInput, SafeAreaView, StyleSheet, Button } from 'react-native'; interface State{ userName: string; userEmail: string; userPassword: string; } interface Props{ } export class App extends React.Component<Props, State>{ constructor(props) { super(props); this.state ={ userName:'', userEmail:'', userPassword:'', }; } userRegister = () =>{ // console.log('Login'); const {userName}=this.state; const {userEmail}=this.state; const {userPassword}=this.state; //console.log(userName); fetch('https://www.howcanfind.com/mobileapp/reg.php',{ method:'post', headers:{ 'Accept':'application/json', 'Content-type':'application/json' }, body:JSON.stringify({ name:userName, email:userEmail, password:userPassword, }) }) .then((response) => response.json()) .then((responseJson)=>{ alert(responseJson); }) .catch((error)=>{ console.error(error); }); } render(){ return( <SafeAreaView style={styles.container}> <TextInput placeholder="Enter Name" style={{width:200,borderWidth:1,margin:10}} onChangeText={userName=>this.setState({userName})} /> <TextInput placeholder="Enter Email" style={{width:200,borderWidth:1,margin:10}} onChangeText={userEmail=>this.setState({userEmail})} /> <TextInput placeholder="Enter Password" style={{width:200,borderWidth:1,margin:10}} onChangeText={userPassword=>this.setState({userPassword})} /> <Button title="Signup" onPress={this.userRegister} /> </SafeAreaView> ) } } const styles = StyleSheet.create({ container:{ flex:1,justifyContent:'center',alignItems:'center' }, });
show toast show output
ToastAndroid,
ToastAndroid.show(responseJson,ToastAndroid.CENTER);
<Text>Sign-up {this.state.userName} </Text>
/** * Sample React Native App * https://github.com/facebook/react-native * * @format * @flow strict-local */ import * as React from 'react'; import{ View, TextInput,ToastAndroid, SafeAreaView, StyleSheet, Text, Button } from 'react-native'; interface State{ userName: string; userEmail: string; userPassword: string; } interface Props{ } export class App extends React.Component<Props, State>{ constructor(props) { super(props); this.state ={ userName:'', userEmail:'', userPassword:'', }; } userRegister = () =>{ // console.log('Login'); const {userName}=this.state; const {userEmail}=this.state; const {userPassword}=this.state; //console.log(userName); fetch('https://www.howcanfind.com/mobileapp/reg.php',{ method:'post', headers:{ 'Accept':'application/json', 'Content-type':'application/json' }, body:JSON.stringify({ name:userName, email:userEmail, password:userPassword, }) }) .then((response) => response.json()) .then((responseJson)=>{ ToastAndroid.show(responseJson,ToastAndroid.CENTER); //alert(responseJson); }) .catch((error)=>{ console.error(error); }); } render(){ return( <SafeAreaView style={styles.container}> <Text>Sign-up {this.state.userName} </Text> <TextInput placeholder="Enter Name" style={{width:200,borderWidth:1,margin:10}} onChangeText={userName=>this.setState({userName})} /> <TextInput placeholder="Enter Email" style={{width:200,borderWidth:1,margin:10}} onChangeText={userEmail=>this.setState({userEmail})} /> <TextInput placeholder="Enter Password" style={{width:200,borderWidth:1,margin:10}} onChangeText={userPassword=>this.setState({userPassword})} /> <Button title="Signup" onPress={this.userRegister} /> </SafeAreaView> ) } } const styles = StyleSheet.create({ container:{ flex:1,justifyContent:'center',alignItems:'center' }, });
jason file php connectwith mysql
<?php include("conn.php"); @$today=date("Y-m-d"); //echo $today; $json = file_get_contents('php://input'); //decoadng the receveid Json and store into $object variable $obj = json_decode($json,true); $mbl = $obj['name']; //echo $mbl; $email = $obj['email']; //echo $email; $pwed = $obj['password']; // $name=$_POST['name']; //$quali=str_replace(","," ",$_POST['qualification']); // $mbl = $_POST['phone']; //$email=$_POST['email']; //$pwed=$_POST['pwed']; $city=$_POST['city']; $state=$_POST['state']; $st = '0'; $six_nr = mt_rand(100000, 999999); $query = mysql_query("SELECT mobile FROM table WHERE mobile=$mbl"); $count = mysql_num_rows($query); if($count == 1) { // echo "User Already Exit"; echo json_encode('User Already Exit'); } else { //$sql="insert into table(name,date,mobile,pwd,eml,status,otppswd) values('".$name."','".$today."','".$mbl."','".$pwed."','".$email."','".$st."','".$six_nr."')"; //echo $sql; $sql="insert into table(name,date,mobile,pwd,eml,status) values('".$name."','".$today."','".$mbl."','".$pwed."','".$email."','".$st."')"; $result= mysql_query($sql) or die(mysql_error()); if($result){ //echo 'Registration form Enter'; echo json_encode('Registration Enter'); } else{ // echo 'No Registration form Enter'; echo json_encode('No Registration Enter'); } } ?>
connection database
<?php $dbhost="localhost"; $dbuser="uername"; $dbpass="passwordlink"; $dbname="databasename"; mysql_connect("$dbhost","$dbuser","$dbpass"); mysql_select_db($dbname) or die("database problem"); ?>