我的本地反应器中的选择器项值未插入数据库

时间:2019-01-24 10:04:07

标签: php react-native

我正在写一个将本机数据发送到mysql数据库的php api的react native表单,但是没有正确插入选择器项目值,当我从查询中将其删除并且它在db中默认为0时,将插入信息。  我将它的数据库结构从int更改为varchar,但是没有用。 这是我的反应本机代码:

func searchRepositories(withQuery query: String,
                        completionHandler: @escaping (([Repository]?) -> Void)) {
    provider?.request(.searchRepo(query: query)) { result in
        switch result {
        case .success(let response):
            do {
                let repositories = try response.map(SearchResults<Repository>.self)
                print(1)
                completionHandler(repositories.items)
            } catch let error {
                print(error.localizedDescription)
            }

        case .failure(let error):
            print(error)
        }
    }
}

}  这是我的php代码:

import React,{Component}  from 'react';
import {TextInput,Picker}from 'react-native';
import {View ,Button,Text,Input} from 'native-base';
import Axios from 'axios';

export default class Reserve extends Component{

constructor(props){
    super(props)
    this.state={
        dateSelection:'',
        timeSelection:'',
        tableSelection:'',
        numOfTables:''
    }
}


reserve = () =>{
    Axios.post('http://192.168.251.2/restaurant/reserve.php', 
            {date:this.state.dateSelection,
            time:this.state.timeSelection,
            table:this.state.tableSelection,
            numOfTables:this.state.numOfTables} );

}

render() {
    return (
        //need to add style
        <View style={{}}>

            <TextInput  
            placeholder="Enter date with this format: year/month/day" 
            style={{width:200,margin:10 }}
            onChangeText= {dateSelection => this.setState({dateSelection})}
            />

            <TextInput  
            placeholder="Enter time" 
            style={{width:200,margin:10 }}
            onChangeText= {timeSelection => this.setState({timeSelection})}

            />

            <Text>table</Text>
            <Picker
            style={{width:'80%'}}
        selectedValue={this.state.tableSelection}
        onValueChange={(itemValue,itemIndex) => this.setState({tableSelection : itemValue})}>


                <Picker.Item label="choose some thing!!" value=""/>
                <Picker.Item label="1-2" value="2" />
                <Picker.Item label="3-5" value="5"/>
                <Picker.Item label="6-8" value="8"/>
                <Picker.Item label="more" value="12"/>
            </Picker>

            <TextInput  
            placeholder="number of tables" 
            style={{width:200,margin:10 }}
            onChangeText= {numOfTables => this.setState({numOfTables})}

            />
            <Button  onPress={()=>this.reserve()}>
            <Text>reserve</Text>
            </Button>
        </View>
    );
}

0 个答案:

没有答案