1

i am trying to build a CRUD web app with reactjs and php and mysql . Insert operation is successful. In edit operation i have to pass an id , which i did as :

<Link  to={"/edit/"+this.props.obj.id} className="btn btn-primary">edit</Link>  </td>

its router navigation is:

 <Route exact path='/edit/:id'> <Edit/> </Route>

and it is working fine. it navigates to the edit route with its id,and then in Edit class i want to get the data from a php page using that id :

class Edit extends Component {
constructor(props) {
    super(props)
    this.onChangeEmail = this.onChangeEmail.bind(this);
    this.onChangePass = this.onChangePass.bind(this);
    this.onSubmit=this.onSubmit.bind(this);

    this.state = {

         email: '',
        password : ''

    }
}

 componentDidMount(props){
     axios.get('/edit.php?id=' + this.props.match.params.id)
     .then(res => this.setState({
         email: res.data.email,
         password :res.data.password
     })).catch(e=> console.log(e))

 }

this doesnt worked for me , but worked for the person where i walkedthrough his videos. Plese help to fix this.

sumitk
  • 11
  • 1

0 Answers0