How do I avoid returning null data using form in reactJS?Check Back-end Code also, Experts give me answer#1054 - Unknown column 'de15a674d1252f6565a65756ebfa97e8e1e58c9c' in 'where clause'FULLTEXT For Search TroublesSelect from three tables - mysql and phpinsert array data into two table using CodeIgniterInsert data to database not working (PHP-SQL)Questions about my Database MySQL and Android StudioUsing email field instead of username field for authentiaction CakePHP 3[23000][1062] Duplicate entry '0' for key 'PRIMARY'CI: Master Detail for User Registration Form doesn't work

Origins of the "array like" strings in BASIC

What are these round pads on the bottom of a PCB?

Do Monks gain the 9th level Unarmored Movement benefit when wearing armor or using a shield?

Magento 2 - Slick slider function not working

Lorentz invariance of Maxwell's equations in matter

Can I bring back Planetary Romance as a genre?

How do I minimise waste on a flight?

Why do the Avengers care about returning these items in Endgame?

How come mathematicians published in Annals of Eugenics?

Can you turn a recording upside-down?

Is it possible to reduce the cost of brewing potions?

Identity of a supposed anonymous referee revealed through "Description" of the report

I might have messed up in the 'Future Work' section of my thesis

Two (probably) equal real numbers which are not proved to be equal?

Fee negotiations in Lightning

Why was Sam Wilson chosen for this, but not Bucky?

What does the "DS" in "DS-..." US visa application forms stand for?

When do you stop "pushing" a book?

My perfect evil overlord plan... or is it?

how to find out if there's files in a folder and exit accordingly (in KSH)

Names of the Six Tastes

Was the Highlands Ranch shooting the 115th mass shooting in the US in 2019

How is Arya still alive?

What is the radius of the circle in this problem?



How do I avoid returning null data using form in reactJS?Check Back-end Code also, Experts give me answer


#1054 - Unknown column 'de15a674d1252f6565a65756ebfa97e8e1e58c9c' in 'where clause'FULLTEXT For Search TroublesSelect from three tables - mysql and phpinsert array data into two table using CodeIgniterInsert data to database not working (PHP-SQL)Questions about my Database MySQL and Android StudioUsing email field instead of username field for authentiaction CakePHP 3[23000][1062] Duplicate entry '0' for key 'PRIMARY'CI: Master Detail for User Registration Form doesn't work






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








3















When I try to type data into reactJs form through the API, the console returns null.



When I refresh the page on the backend CodeIgniter, it then displays the key values in the form of null.



How can I fix the problem data so that the console does not return null when I input through a reachJS form.



For instance, when I type in browser http://localhost/API/UserController/users, it returns null on every response of the reactJs form as follows:



"user_id":"119","UserName":null,"user_email":null,"Password":null,"CreatedDate":"0000-00-00 00:00:00","Status":null,"Role":null,"VendorId":null


When I check the code in
http://localhost/API/UserController/insertUsers, only the insertUser controller returns null.



Any input in regards to the problem would be appreciated.

My database code is:



CREATE TABLE `users`(
`user_id` int(11) NOT NULL,
`UserName` varchar(255) DEFAULT NULL,
`user_email` varchar(40) DEFAULT NULL,
`Password` varchar(1000) DEFAULT NULL,
`CreatedDate` datetime DEFAULT NULL,
`Status` int(11) DEFAULT NULL
`Role` varchar(255) DEFAULT NULL,
`VendorId` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


My Usermodel in CodeIgniter is:



class Usermodel extends CI_Model


public function get_users()
$query = $this->db->select("*")
->from("users")
->get();
return $query;

public function insert_users($data)
$this->UserName = $data['UserName'];
$this->user_email=$data['user_email'];
$this->Password =$data['Password'];
$this->CreatedDate=$data['CreatedDate'];
$this->Status=$data['Status'];
$this->Role = $data['Role'];
$this->VendorId=$data['VendorId'];
$this->db->insert("users",$this);




My UserController Controller in insertUsers Method is:



<?php 
defined('BASEPATH') OR exit('No direct script access allowed');
header('Access-Control-Allow-Origin: *');
if($_SERVER['REQUEST_METHOD']==='OPTIONS')
header('Access-Control-Allow-Methods:GET,PUT,POST,DELETE,OPTIONS');
header('Access-Control-Allow-Headers:Content-Type');
exit;

class UserController extends CI_Controller

function __construct()

parent::__construct();
$this->load->model("usermodel","us");

public function users()
$query = $this->us->get_users();
header("Content_Type:application/json");
echo json_encode($query->result());

public function insertUsers()
$data = array(
'UserName' =>$this->input->post('UserName') ,
'user_email' =>$this->input->post('user_email'),
'Password' =>$this->input->post('Password'),
'CreatedDate' =>date("l jS of F Y h:i:s A"),
'Status' =>$this->input->post('Status'),
'Role' => $this->input->post('Role'),
'VendorId' => $this->input->post('VendorId'),
);
$query =$this->us->insert_users($data);
header("Content_Type:application/json");
echo json_encode($query);




Additionally, I fetch the API using reactJS, and when the user writes any data in form, it returns null in response Register.js as follows:



import React, Component from 'react';
import Button, Card, CardBody, CardFooter, Col, Container, Form, Input, InputGroup, InputGroupAddon, InputGroupText, Row from 'reactstrap';

class Register extends Component
constructor(props)
super(props);
this.state =
user_id:'', Username:'', Password:'', user_email:'',CreatedDate:'',Status:'',Role:'',VendorId:'',

this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);

handleChange(event)
const state = this.state;
state[event.target.name] = event.target.value;
this.setState(state, () => console.log(state));
// console.log(state); state get undefined


handleSubmit(event)
event.preventDefault();
fetch('http://localhost/API/UserController/insertUsers',
method:'POST',
headers:
'Content-Type':'application/json',
'Accept':'application/json'
,
body:JSON.stringify(
user_id :this.state.user_id,
Username:this.state.Username,
Password:this.state.Password,
user_email:this.state.user_email,
CreatedDate:this.state.CreatedDate,
Status:this.state.Status,
Role: this.state.Role,
VendorId:this.state.VendorId,
)
)
.then(res =>res.json() )
.then(data => console.log(data))
.catch(err => console.log("show me error that cannot be specify",err))

render()
return (
<div className="app flex-row align-items-center">
<Container>
<Row className="justify-content-center">
<Col md="9" lg="7" xl="6">
<Card className="mx-4">
<CardBody className="p-4">
<Form action="http://localhost/API/UserController/users" method="post" onSubmit=this.handleSubmit>
<h1>Register</h1>
<p className="text-muted">Create your account</p>
<InputGroup className="mb-3">
<InputGroupAddon addonType="prepend">
<InputGroupText>
<i className="icon-user"></i>
</InputGroupText>
</InputGroupAddon>
<Input required type="text" name="UserName" value=this.state.UserName onChange=this.handleChange placeholder="Username" autoComplete="username" name="Username" />
</InputGroup>
<InputGroup className="mb-3">
<InputGroupAddon addonType="prepend">
<InputGroupText>@</InputGroupText>
</InputGroupAddon>
<Input required type="text" placeholder="User email" name="user_email" value=this.state.user_email onChange=this.handleChange autoComplete="email" />
</InputGroup>
<InputGroup className="mb-3">
<InputGroupAddon addonType="prepend">
<InputGroupText>
<i className="icon-lock"></i>
</InputGroupText>
</InputGroupAddon>
<Input required type="password" placeholder="Password" value=this.state.Password onChange=this.handleChange name="Password" autoComplete="new-password" />
</InputGroup>
<Button color="success" block>Create Account</Button>
</Form>
</CardBody>
<CardFooter className="p-4">
<Row>
<Col xs="12" sm="6">
<Button className="btn-facebook mb-1" block><span>facebook</span></Button>
</Col>
<Col xs="12" sm="6">
<Button className="btn-twitter mb-1" block><span>twitter</span></Button>
</Col>
</Row>
</CardFooter>
</Card>
</Col>
</Row>
</Container>
</div>
);



export default Register;









share|improve this question






























    3















    When I try to type data into reactJs form through the API, the console returns null.



    When I refresh the page on the backend CodeIgniter, it then displays the key values in the form of null.



    How can I fix the problem data so that the console does not return null when I input through a reachJS form.



    For instance, when I type in browser http://localhost/API/UserController/users, it returns null on every response of the reactJs form as follows:



    "user_id":"119","UserName":null,"user_email":null,"Password":null,"CreatedDate":"0000-00-00 00:00:00","Status":null,"Role":null,"VendorId":null


    When I check the code in
    http://localhost/API/UserController/insertUsers, only the insertUser controller returns null.



    Any input in regards to the problem would be appreciated.

    My database code is:



    CREATE TABLE `users`(
    `user_id` int(11) NOT NULL,
    `UserName` varchar(255) DEFAULT NULL,
    `user_email` varchar(40) DEFAULT NULL,
    `Password` varchar(1000) DEFAULT NULL,
    `CreatedDate` datetime DEFAULT NULL,
    `Status` int(11) DEFAULT NULL
    `Role` varchar(255) DEFAULT NULL,
    `VendorId` int(11) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;


    My Usermodel in CodeIgniter is:



    class Usermodel extends CI_Model


    public function get_users()
    $query = $this->db->select("*")
    ->from("users")
    ->get();
    return $query;

    public function insert_users($data)
    $this->UserName = $data['UserName'];
    $this->user_email=$data['user_email'];
    $this->Password =$data['Password'];
    $this->CreatedDate=$data['CreatedDate'];
    $this->Status=$data['Status'];
    $this->Role = $data['Role'];
    $this->VendorId=$data['VendorId'];
    $this->db->insert("users",$this);




    My UserController Controller in insertUsers Method is:



    <?php 
    defined('BASEPATH') OR exit('No direct script access allowed');
    header('Access-Control-Allow-Origin: *');
    if($_SERVER['REQUEST_METHOD']==='OPTIONS')
    header('Access-Control-Allow-Methods:GET,PUT,POST,DELETE,OPTIONS');
    header('Access-Control-Allow-Headers:Content-Type');
    exit;

    class UserController extends CI_Controller

    function __construct()

    parent::__construct();
    $this->load->model("usermodel","us");

    public function users()
    $query = $this->us->get_users();
    header("Content_Type:application/json");
    echo json_encode($query->result());

    public function insertUsers()
    $data = array(
    'UserName' =>$this->input->post('UserName') ,
    'user_email' =>$this->input->post('user_email'),
    'Password' =>$this->input->post('Password'),
    'CreatedDate' =>date("l jS of F Y h:i:s A"),
    'Status' =>$this->input->post('Status'),
    'Role' => $this->input->post('Role'),
    'VendorId' => $this->input->post('VendorId'),
    );
    $query =$this->us->insert_users($data);
    header("Content_Type:application/json");
    echo json_encode($query);




    Additionally, I fetch the API using reactJS, and when the user writes any data in form, it returns null in response Register.js as follows:



    import React, Component from 'react';
    import Button, Card, CardBody, CardFooter, Col, Container, Form, Input, InputGroup, InputGroupAddon, InputGroupText, Row from 'reactstrap';

    class Register extends Component
    constructor(props)
    super(props);
    this.state =
    user_id:'', Username:'', Password:'', user_email:'',CreatedDate:'',Status:'',Role:'',VendorId:'',

    this.handleChange = this.handleChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);

    handleChange(event)
    const state = this.state;
    state[event.target.name] = event.target.value;
    this.setState(state, () => console.log(state));
    // console.log(state); state get undefined


    handleSubmit(event)
    event.preventDefault();
    fetch('http://localhost/API/UserController/insertUsers',
    method:'POST',
    headers:
    'Content-Type':'application/json',
    'Accept':'application/json'
    ,
    body:JSON.stringify(
    user_id :this.state.user_id,
    Username:this.state.Username,
    Password:this.state.Password,
    user_email:this.state.user_email,
    CreatedDate:this.state.CreatedDate,
    Status:this.state.Status,
    Role: this.state.Role,
    VendorId:this.state.VendorId,
    )
    )
    .then(res =>res.json() )
    .then(data => console.log(data))
    .catch(err => console.log("show me error that cannot be specify",err))

    render()
    return (
    <div className="app flex-row align-items-center">
    <Container>
    <Row className="justify-content-center">
    <Col md="9" lg="7" xl="6">
    <Card className="mx-4">
    <CardBody className="p-4">
    <Form action="http://localhost/API/UserController/users" method="post" onSubmit=this.handleSubmit>
    <h1>Register</h1>
    <p className="text-muted">Create your account</p>
    <InputGroup className="mb-3">
    <InputGroupAddon addonType="prepend">
    <InputGroupText>
    <i className="icon-user"></i>
    </InputGroupText>
    </InputGroupAddon>
    <Input required type="text" name="UserName" value=this.state.UserName onChange=this.handleChange placeholder="Username" autoComplete="username" name="Username" />
    </InputGroup>
    <InputGroup className="mb-3">
    <InputGroupAddon addonType="prepend">
    <InputGroupText>@</InputGroupText>
    </InputGroupAddon>
    <Input required type="text" placeholder="User email" name="user_email" value=this.state.user_email onChange=this.handleChange autoComplete="email" />
    </InputGroup>
    <InputGroup className="mb-3">
    <InputGroupAddon addonType="prepend">
    <InputGroupText>
    <i className="icon-lock"></i>
    </InputGroupText>
    </InputGroupAddon>
    <Input required type="password" placeholder="Password" value=this.state.Password onChange=this.handleChange name="Password" autoComplete="new-password" />
    </InputGroup>
    <Button color="success" block>Create Account</Button>
    </Form>
    </CardBody>
    <CardFooter className="p-4">
    <Row>
    <Col xs="12" sm="6">
    <Button className="btn-facebook mb-1" block><span>facebook</span></Button>
    </Col>
    <Col xs="12" sm="6">
    <Button className="btn-twitter mb-1" block><span>twitter</span></Button>
    </Col>
    </Row>
    </CardFooter>
    </Card>
    </Col>
    </Row>
    </Container>
    </div>
    );



    export default Register;









    share|improve this question


























      3












      3








      3


      1






      When I try to type data into reactJs form through the API, the console returns null.



      When I refresh the page on the backend CodeIgniter, it then displays the key values in the form of null.



      How can I fix the problem data so that the console does not return null when I input through a reachJS form.



      For instance, when I type in browser http://localhost/API/UserController/users, it returns null on every response of the reactJs form as follows:



      "user_id":"119","UserName":null,"user_email":null,"Password":null,"CreatedDate":"0000-00-00 00:00:00","Status":null,"Role":null,"VendorId":null


      When I check the code in
      http://localhost/API/UserController/insertUsers, only the insertUser controller returns null.



      Any input in regards to the problem would be appreciated.

      My database code is:



      CREATE TABLE `users`(
      `user_id` int(11) NOT NULL,
      `UserName` varchar(255) DEFAULT NULL,
      `user_email` varchar(40) DEFAULT NULL,
      `Password` varchar(1000) DEFAULT NULL,
      `CreatedDate` datetime DEFAULT NULL,
      `Status` int(11) DEFAULT NULL
      `Role` varchar(255) DEFAULT NULL,
      `VendorId` int(11) DEFAULT NULL
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1;


      My Usermodel in CodeIgniter is:



      class Usermodel extends CI_Model


      public function get_users()
      $query = $this->db->select("*")
      ->from("users")
      ->get();
      return $query;

      public function insert_users($data)
      $this->UserName = $data['UserName'];
      $this->user_email=$data['user_email'];
      $this->Password =$data['Password'];
      $this->CreatedDate=$data['CreatedDate'];
      $this->Status=$data['Status'];
      $this->Role = $data['Role'];
      $this->VendorId=$data['VendorId'];
      $this->db->insert("users",$this);




      My UserController Controller in insertUsers Method is:



      <?php 
      defined('BASEPATH') OR exit('No direct script access allowed');
      header('Access-Control-Allow-Origin: *');
      if($_SERVER['REQUEST_METHOD']==='OPTIONS')
      header('Access-Control-Allow-Methods:GET,PUT,POST,DELETE,OPTIONS');
      header('Access-Control-Allow-Headers:Content-Type');
      exit;

      class UserController extends CI_Controller

      function __construct()

      parent::__construct();
      $this->load->model("usermodel","us");

      public function users()
      $query = $this->us->get_users();
      header("Content_Type:application/json");
      echo json_encode($query->result());

      public function insertUsers()
      $data = array(
      'UserName' =>$this->input->post('UserName') ,
      'user_email' =>$this->input->post('user_email'),
      'Password' =>$this->input->post('Password'),
      'CreatedDate' =>date("l jS of F Y h:i:s A"),
      'Status' =>$this->input->post('Status'),
      'Role' => $this->input->post('Role'),
      'VendorId' => $this->input->post('VendorId'),
      );
      $query =$this->us->insert_users($data);
      header("Content_Type:application/json");
      echo json_encode($query);




      Additionally, I fetch the API using reactJS, and when the user writes any data in form, it returns null in response Register.js as follows:



      import React, Component from 'react';
      import Button, Card, CardBody, CardFooter, Col, Container, Form, Input, InputGroup, InputGroupAddon, InputGroupText, Row from 'reactstrap';

      class Register extends Component
      constructor(props)
      super(props);
      this.state =
      user_id:'', Username:'', Password:'', user_email:'',CreatedDate:'',Status:'',Role:'',VendorId:'',

      this.handleChange = this.handleChange.bind(this);
      this.handleSubmit = this.handleSubmit.bind(this);

      handleChange(event)
      const state = this.state;
      state[event.target.name] = event.target.value;
      this.setState(state, () => console.log(state));
      // console.log(state); state get undefined


      handleSubmit(event)
      event.preventDefault();
      fetch('http://localhost/API/UserController/insertUsers',
      method:'POST',
      headers:
      'Content-Type':'application/json',
      'Accept':'application/json'
      ,
      body:JSON.stringify(
      user_id :this.state.user_id,
      Username:this.state.Username,
      Password:this.state.Password,
      user_email:this.state.user_email,
      CreatedDate:this.state.CreatedDate,
      Status:this.state.Status,
      Role: this.state.Role,
      VendorId:this.state.VendorId,
      )
      )
      .then(res =>res.json() )
      .then(data => console.log(data))
      .catch(err => console.log("show me error that cannot be specify",err))

      render()
      return (
      <div className="app flex-row align-items-center">
      <Container>
      <Row className="justify-content-center">
      <Col md="9" lg="7" xl="6">
      <Card className="mx-4">
      <CardBody className="p-4">
      <Form action="http://localhost/API/UserController/users" method="post" onSubmit=this.handleSubmit>
      <h1>Register</h1>
      <p className="text-muted">Create your account</p>
      <InputGroup className="mb-3">
      <InputGroupAddon addonType="prepend">
      <InputGroupText>
      <i className="icon-user"></i>
      </InputGroupText>
      </InputGroupAddon>
      <Input required type="text" name="UserName" value=this.state.UserName onChange=this.handleChange placeholder="Username" autoComplete="username" name="Username" />
      </InputGroup>
      <InputGroup className="mb-3">
      <InputGroupAddon addonType="prepend">
      <InputGroupText>@</InputGroupText>
      </InputGroupAddon>
      <Input required type="text" placeholder="User email" name="user_email" value=this.state.user_email onChange=this.handleChange autoComplete="email" />
      </InputGroup>
      <InputGroup className="mb-3">
      <InputGroupAddon addonType="prepend">
      <InputGroupText>
      <i className="icon-lock"></i>
      </InputGroupText>
      </InputGroupAddon>
      <Input required type="password" placeholder="Password" value=this.state.Password onChange=this.handleChange name="Password" autoComplete="new-password" />
      </InputGroup>
      <Button color="success" block>Create Account</Button>
      </Form>
      </CardBody>
      <CardFooter className="p-4">
      <Row>
      <Col xs="12" sm="6">
      <Button className="btn-facebook mb-1" block><span>facebook</span></Button>
      </Col>
      <Col xs="12" sm="6">
      <Button className="btn-twitter mb-1" block><span>twitter</span></Button>
      </Col>
      </Row>
      </CardFooter>
      </Card>
      </Col>
      </Row>
      </Container>
      </div>
      );



      export default Register;









      share|improve this question
















      When I try to type data into reactJs form through the API, the console returns null.



      When I refresh the page on the backend CodeIgniter, it then displays the key values in the form of null.



      How can I fix the problem data so that the console does not return null when I input through a reachJS form.



      For instance, when I type in browser http://localhost/API/UserController/users, it returns null on every response of the reactJs form as follows:



      "user_id":"119","UserName":null,"user_email":null,"Password":null,"CreatedDate":"0000-00-00 00:00:00","Status":null,"Role":null,"VendorId":null


      When I check the code in
      http://localhost/API/UserController/insertUsers, only the insertUser controller returns null.



      Any input in regards to the problem would be appreciated.

      My database code is:



      CREATE TABLE `users`(
      `user_id` int(11) NOT NULL,
      `UserName` varchar(255) DEFAULT NULL,
      `user_email` varchar(40) DEFAULT NULL,
      `Password` varchar(1000) DEFAULT NULL,
      `CreatedDate` datetime DEFAULT NULL,
      `Status` int(11) DEFAULT NULL
      `Role` varchar(255) DEFAULT NULL,
      `VendorId` int(11) DEFAULT NULL
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1;


      My Usermodel in CodeIgniter is:



      class Usermodel extends CI_Model


      public function get_users()
      $query = $this->db->select("*")
      ->from("users")
      ->get();
      return $query;

      public function insert_users($data)
      $this->UserName = $data['UserName'];
      $this->user_email=$data['user_email'];
      $this->Password =$data['Password'];
      $this->CreatedDate=$data['CreatedDate'];
      $this->Status=$data['Status'];
      $this->Role = $data['Role'];
      $this->VendorId=$data['VendorId'];
      $this->db->insert("users",$this);




      My UserController Controller in insertUsers Method is:



      <?php 
      defined('BASEPATH') OR exit('No direct script access allowed');
      header('Access-Control-Allow-Origin: *');
      if($_SERVER['REQUEST_METHOD']==='OPTIONS')
      header('Access-Control-Allow-Methods:GET,PUT,POST,DELETE,OPTIONS');
      header('Access-Control-Allow-Headers:Content-Type');
      exit;

      class UserController extends CI_Controller

      function __construct()

      parent::__construct();
      $this->load->model("usermodel","us");

      public function users()
      $query = $this->us->get_users();
      header("Content_Type:application/json");
      echo json_encode($query->result());

      public function insertUsers()
      $data = array(
      'UserName' =>$this->input->post('UserName') ,
      'user_email' =>$this->input->post('user_email'),
      'Password' =>$this->input->post('Password'),
      'CreatedDate' =>date("l jS of F Y h:i:s A"),
      'Status' =>$this->input->post('Status'),
      'Role' => $this->input->post('Role'),
      'VendorId' => $this->input->post('VendorId'),
      );
      $query =$this->us->insert_users($data);
      header("Content_Type:application/json");
      echo json_encode($query);




      Additionally, I fetch the API using reactJS, and when the user writes any data in form, it returns null in response Register.js as follows:



      import React, Component from 'react';
      import Button, Card, CardBody, CardFooter, Col, Container, Form, Input, InputGroup, InputGroupAddon, InputGroupText, Row from 'reactstrap';

      class Register extends Component
      constructor(props)
      super(props);
      this.state =
      user_id:'', Username:'', Password:'', user_email:'',CreatedDate:'',Status:'',Role:'',VendorId:'',

      this.handleChange = this.handleChange.bind(this);
      this.handleSubmit = this.handleSubmit.bind(this);

      handleChange(event)
      const state = this.state;
      state[event.target.name] = event.target.value;
      this.setState(state, () => console.log(state));
      // console.log(state); state get undefined


      handleSubmit(event)
      event.preventDefault();
      fetch('http://localhost/API/UserController/insertUsers',
      method:'POST',
      headers:
      'Content-Type':'application/json',
      'Accept':'application/json'
      ,
      body:JSON.stringify(
      user_id :this.state.user_id,
      Username:this.state.Username,
      Password:this.state.Password,
      user_email:this.state.user_email,
      CreatedDate:this.state.CreatedDate,
      Status:this.state.Status,
      Role: this.state.Role,
      VendorId:this.state.VendorId,
      )
      )
      .then(res =>res.json() )
      .then(data => console.log(data))
      .catch(err => console.log("show me error that cannot be specify",err))

      render()
      return (
      <div className="app flex-row align-items-center">
      <Container>
      <Row className="justify-content-center">
      <Col md="9" lg="7" xl="6">
      <Card className="mx-4">
      <CardBody className="p-4">
      <Form action="http://localhost/API/UserController/users" method="post" onSubmit=this.handleSubmit>
      <h1>Register</h1>
      <p className="text-muted">Create your account</p>
      <InputGroup className="mb-3">
      <InputGroupAddon addonType="prepend">
      <InputGroupText>
      <i className="icon-user"></i>
      </InputGroupText>
      </InputGroupAddon>
      <Input required type="text" name="UserName" value=this.state.UserName onChange=this.handleChange placeholder="Username" autoComplete="username" name="Username" />
      </InputGroup>
      <InputGroup className="mb-3">
      <InputGroupAddon addonType="prepend">
      <InputGroupText>@</InputGroupText>
      </InputGroupAddon>
      <Input required type="text" placeholder="User email" name="user_email" value=this.state.user_email onChange=this.handleChange autoComplete="email" />
      </InputGroup>
      <InputGroup className="mb-3">
      <InputGroupAddon addonType="prepend">
      <InputGroupText>
      <i className="icon-lock"></i>
      </InputGroupText>
      </InputGroupAddon>
      <Input required type="password" placeholder="Password" value=this.state.Password onChange=this.handleChange name="Password" autoComplete="new-password" />
      </InputGroup>
      <Button color="success" block>Create Account</Button>
      </Form>
      </CardBody>
      <CardFooter className="p-4">
      <Row>
      <Col xs="12" sm="6">
      <Button className="btn-facebook mb-1" block><span>facebook</span></Button>
      </Col>
      <Col xs="12" sm="6">
      <Button className="btn-twitter mb-1" block><span>twitter</span></Button>
      </Col>
      </Row>
      </CardFooter>
      </Card>
      </Col>
      </Row>
      </Container>
      </div>
      );



      export default Register;






      php mysql reactjs codeigniter-3






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 18 at 14:40









      Your Common Sense

      133k21146256




      133k21146256










      asked Mar 23 at 5:07









      KashifKashif

      588




      588






















          2 Answers
          2






          active

          oldest

          votes


















          0














          CodeIgniter does not return data or a result set when you perform write operations like insert or update on a database, it returns a boolean instead (true/false).
          Thus why you're getting null, the value of $query here



          $query = $this->us->insert_users($data);


          Will be true if the operation is successful, else will be false.



          Use an if statement to check if true and return $data instead



          echo json_encode($data);


          You can checkout CI (CodeIgniter)'s documentation on queries here
          https://www.codeigniter.com/user_guide/database/queries.html



          I also suggest you use an encryption algorithm to encrypt your password.






          share|improve this answer

























          • in this way show me true but if i can input data through ReactJs form then show me all fields null when i check localhost/API/UserController/users controller

            – Kashif
            Mar 27 at 3:44












          • i update my model query then it's working for me public function insert_users($data) return $this->db->insert("users",$data); show me true But when i input data from ReactJs form then check localhost/API/UserController/users controller and refresh it then add new record in it in the form of null like that "user_id":"305","UserName":null,"user_email":null,"Password":null,"CreatedDate":"0000-00-00 00:00:00","Status":null,"Role":null,"VendorId":null

            – Kashif
            Mar 27 at 3:51












          • If I understand correctly, the insert functionality works fine, but the 'localhost/API/UserController/users' is not showing any result?

            – Femi_DD
            Mar 27 at 5:00











          • showing result but in the form of null ,like that "user_id":"305","UserName":null,"user_email":null,"Password":null,"CreatedDate":"0000-00-00 00:00:00","Status":null,"Role":null,"VendorId":null

            – Kashif
            Mar 27 at 15:55











          • in database data add in the form of null when i input any data using react form new record add in database and also in localhost/API/UserController/users controller

            – Kashif
            Mar 27 at 16:03


















          0














          Usermodel



          <?php
          defined('BASEPATH') OR exit('No direct script access allowed');
          class Usermodel extends CI_model

          public function get_users()

          $this->db->where('is_active', 1);
          $query = $this->db->get('users');
          return $query->result();


          public function insert_users($formData)

          $this->db->insert('users', $formData);
          return $this->db->insert_id();




          My UserController Controller in insertUsers Method is:



          <?php
          defined('BASEPATH') OR exit('No direct script access allowed');
          class UserController extends CI_Controller
          public function __construct()

          parent::__construct();
          $this->load->model('Usermodel');


          public function users()

          header("Access-Control-Allow-Origin: *");
          $users = $this->Usermodel->get_users();

          $this->output
          ->set_content_type('application/json')
          ->set_output(json_encode($users));




          public function insertUsers()

          header("Access-Control-Allow-Origin: *");
          header("Access-Control-Request-Headers: GET,POST,OPTIONS,DELETE,PUT");

          $formdata = json_decode(file_get_contents('php://input'), true);

          if( ! empty($formdata))

          $UserName = $formdata['UserName'];
          $user_email = $formdata['user_email'];
          $Password = $formdata['Password'];

          $userData = array(
          'UserName' => $UserName,
          'user_email' => $user_email,
          'Password' => password_hash($Password,PASSWORD_DEFAULT),
          'is_active' => 1,
          'created_at' => date('Y-m-d H', time())
          );

          $id = $this->Usermodel->insert_users($userData);

          $response = array(
          'status' => 'success',
          'message' => 'User Register successfully'
          );

          else
          $response = array(
          'status' => 'error'
          );


          $this->output
          ->set_content_type('application/json')
          ->set_output(json_encode($response));




          Register.js code store data in database now



          import React, Component from 'react';
          import Button, Card, CardBody, CardFooter, Col, Container,Alert, Form, Input, InputGroup, InputGroupAddon, InputGroupText, Row from 'reactstrap';
          class Register extends Component
          constructor(props)
          super(props);
          this.state =
          Username:'',
          user_email:'',
          Password:'',
          error:null,
          response:,

          this.onFormSubmit = this.onFormSubmit.bind(this);
          this.handleChange = this.handleChange.bind(this);
          this.handleSubmit = this.handleSubmit.bind(this);

          handleChange(event)
          const name = event.target.name;
          const value = event.target.value;

          this.setState(
          [name]: value
          );


          handleSubmit=(event)=>
          event.preventDefault();
          this.onFormSubmit(this.state);
          this.setState(this.state);


          onFormSubmit(data)
          const apiUrl = "http://localhost/API/UserController/insertUsers";
          const myHeaders = new Headers();
          myHeaders.append('Content-Type','application/json');
          const options =
          method:'POST',
          body:JSON.stringify(data),
          myHeaders
          ;
          fetch(apiUrl,options)
          .then(res => res.json() )
          .then(result =>
          this.setState(
          response:result,
          );
          )
          .then(error=>
          this.setState(
          error
          );
          );

          this.setState(
          Username:'',
          user_email:'',
          Password:''
          );

          render()
          return (
          <div className="app flex-row align-items-center">
          <Container>
          <Row className="justify-content-center">
          <Col md="9" lg="7" xl="6">
          <Card className="mx-4">
          <CardBody className="p-4">
          <Form onSubmit=this.handleSubmit>
          <h1>Register</h1>
          <p className="text-muted">Create your account</p>
          <InputGroup className="mb-3">
          <InputGroupAddon addonType="prepend">
          <InputGroupText>
          <i className="icon-user"></i>
          </InputGroupText>
          </InputGroupAddon>
          <Input type="text" name="UserName" value=this.state.UserName onChange=this.handleChange placeholder="Username" autoComplete="username" />
          </InputGroup>
          <InputGroup className="mb-3">
          <InputGroupAddon addonType="prepend">
          <InputGroupText>@</InputGroupText>
          </InputGroupAddon>
          <Input type="text" placeholder="User email" name="user_email" value=this.state.user_email onChange=this.handleChange autoComplete="email" />
          </InputGroup>
          <InputGroup className="mb-3">
          <InputGroupAddon addonType="prepend">
          <InputGroupText>
          <i className="icon-lock"></i>
          </InputGroupText>
          </InputGroupAddon>
          <Input type="password" placeholder="Password" value=this.state.Password onChange=this.handleChange name="Password" autoComplete="new-password" />
          </InputGroup>
          <Button color="success" block>Create Account</Button>
          </Form>
          </CardBody>
          <CardFooter className="p-4">
          <Row>
          <Col xs="12" sm="6">
          <Button className="btn-facebook mb-1" block><span>facebook</span></Button>
          </Col>
          <Col xs="12" sm="6">
          <Button className="btn-twitter mb-1" block><span>twitter</span></Button>
          </Col>
          </Row>
          </CardFooter>
          </Card>
          </Col>
          </Row>
          </Container>
          this.state.response.status === 'success' && <div><br /><Alert variant="info">this.state.response.message</Alert></div>
          this.state.error && <div>Error: this.state.error.message</div>
          </div>
          );


          export default Register;





          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55310807%2fhow-do-i-avoid-returning-null-data-using-form-in-reactjscheck-back-end-code-als%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            CodeIgniter does not return data or a result set when you perform write operations like insert or update on a database, it returns a boolean instead (true/false).
            Thus why you're getting null, the value of $query here



            $query = $this->us->insert_users($data);


            Will be true if the operation is successful, else will be false.



            Use an if statement to check if true and return $data instead



            echo json_encode($data);


            You can checkout CI (CodeIgniter)'s documentation on queries here
            https://www.codeigniter.com/user_guide/database/queries.html



            I also suggest you use an encryption algorithm to encrypt your password.






            share|improve this answer

























            • in this way show me true but if i can input data through ReactJs form then show me all fields null when i check localhost/API/UserController/users controller

              – Kashif
              Mar 27 at 3:44












            • i update my model query then it's working for me public function insert_users($data) return $this->db->insert("users",$data); show me true But when i input data from ReactJs form then check localhost/API/UserController/users controller and refresh it then add new record in it in the form of null like that "user_id":"305","UserName":null,"user_email":null,"Password":null,"CreatedDate":"0000-00-00 00:00:00","Status":null,"Role":null,"VendorId":null

              – Kashif
              Mar 27 at 3:51












            • If I understand correctly, the insert functionality works fine, but the 'localhost/API/UserController/users' is not showing any result?

              – Femi_DD
              Mar 27 at 5:00











            • showing result but in the form of null ,like that "user_id":"305","UserName":null,"user_email":null,"Password":null,"CreatedDate":"0000-00-00 00:00:00","Status":null,"Role":null,"VendorId":null

              – Kashif
              Mar 27 at 15:55











            • in database data add in the form of null when i input any data using react form new record add in database and also in localhost/API/UserController/users controller

              – Kashif
              Mar 27 at 16:03















            0














            CodeIgniter does not return data or a result set when you perform write operations like insert or update on a database, it returns a boolean instead (true/false).
            Thus why you're getting null, the value of $query here



            $query = $this->us->insert_users($data);


            Will be true if the operation is successful, else will be false.



            Use an if statement to check if true and return $data instead



            echo json_encode($data);


            You can checkout CI (CodeIgniter)'s documentation on queries here
            https://www.codeigniter.com/user_guide/database/queries.html



            I also suggest you use an encryption algorithm to encrypt your password.






            share|improve this answer

























            • in this way show me true but if i can input data through ReactJs form then show me all fields null when i check localhost/API/UserController/users controller

              – Kashif
              Mar 27 at 3:44












            • i update my model query then it's working for me public function insert_users($data) return $this->db->insert("users",$data); show me true But when i input data from ReactJs form then check localhost/API/UserController/users controller and refresh it then add new record in it in the form of null like that "user_id":"305","UserName":null,"user_email":null,"Password":null,"CreatedDate":"0000-00-00 00:00:00","Status":null,"Role":null,"VendorId":null

              – Kashif
              Mar 27 at 3:51












            • If I understand correctly, the insert functionality works fine, but the 'localhost/API/UserController/users' is not showing any result?

              – Femi_DD
              Mar 27 at 5:00











            • showing result but in the form of null ,like that "user_id":"305","UserName":null,"user_email":null,"Password":null,"CreatedDate":"0000-00-00 00:00:00","Status":null,"Role":null,"VendorId":null

              – Kashif
              Mar 27 at 15:55











            • in database data add in the form of null when i input any data using react form new record add in database and also in localhost/API/UserController/users controller

              – Kashif
              Mar 27 at 16:03













            0












            0








            0







            CodeIgniter does not return data or a result set when you perform write operations like insert or update on a database, it returns a boolean instead (true/false).
            Thus why you're getting null, the value of $query here



            $query = $this->us->insert_users($data);


            Will be true if the operation is successful, else will be false.



            Use an if statement to check if true and return $data instead



            echo json_encode($data);


            You can checkout CI (CodeIgniter)'s documentation on queries here
            https://www.codeigniter.com/user_guide/database/queries.html



            I also suggest you use an encryption algorithm to encrypt your password.






            share|improve this answer















            CodeIgniter does not return data or a result set when you perform write operations like insert or update on a database, it returns a boolean instead (true/false).
            Thus why you're getting null, the value of $query here



            $query = $this->us->insert_users($data);


            Will be true if the operation is successful, else will be false.



            Use an if statement to check if true and return $data instead



            echo json_encode($data);


            You can checkout CI (CodeIgniter)'s documentation on queries here
            https://www.codeigniter.com/user_guide/database/queries.html



            I also suggest you use an encryption algorithm to encrypt your password.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 26 at 3:19

























            answered Mar 26 at 2:06









            Femi_DDFemi_DD

            1616




            1616












            • in this way show me true but if i can input data through ReactJs form then show me all fields null when i check localhost/API/UserController/users controller

              – Kashif
              Mar 27 at 3:44












            • i update my model query then it's working for me public function insert_users($data) return $this->db->insert("users",$data); show me true But when i input data from ReactJs form then check localhost/API/UserController/users controller and refresh it then add new record in it in the form of null like that "user_id":"305","UserName":null,"user_email":null,"Password":null,"CreatedDate":"0000-00-00 00:00:00","Status":null,"Role":null,"VendorId":null

              – Kashif
              Mar 27 at 3:51












            • If I understand correctly, the insert functionality works fine, but the 'localhost/API/UserController/users' is not showing any result?

              – Femi_DD
              Mar 27 at 5:00











            • showing result but in the form of null ,like that "user_id":"305","UserName":null,"user_email":null,"Password":null,"CreatedDate":"0000-00-00 00:00:00","Status":null,"Role":null,"VendorId":null

              – Kashif
              Mar 27 at 15:55











            • in database data add in the form of null when i input any data using react form new record add in database and also in localhost/API/UserController/users controller

              – Kashif
              Mar 27 at 16:03

















            • in this way show me true but if i can input data through ReactJs form then show me all fields null when i check localhost/API/UserController/users controller

              – Kashif
              Mar 27 at 3:44












            • i update my model query then it's working for me public function insert_users($data) return $this->db->insert("users",$data); show me true But when i input data from ReactJs form then check localhost/API/UserController/users controller and refresh it then add new record in it in the form of null like that "user_id":"305","UserName":null,"user_email":null,"Password":null,"CreatedDate":"0000-00-00 00:00:00","Status":null,"Role":null,"VendorId":null

              – Kashif
              Mar 27 at 3:51












            • If I understand correctly, the insert functionality works fine, but the 'localhost/API/UserController/users' is not showing any result?

              – Femi_DD
              Mar 27 at 5:00











            • showing result but in the form of null ,like that "user_id":"305","UserName":null,"user_email":null,"Password":null,"CreatedDate":"0000-00-00 00:00:00","Status":null,"Role":null,"VendorId":null

              – Kashif
              Mar 27 at 15:55











            • in database data add in the form of null when i input any data using react form new record add in database and also in localhost/API/UserController/users controller

              – Kashif
              Mar 27 at 16:03
















            in this way show me true but if i can input data through ReactJs form then show me all fields null when i check localhost/API/UserController/users controller

            – Kashif
            Mar 27 at 3:44






            in this way show me true but if i can input data through ReactJs form then show me all fields null when i check localhost/API/UserController/users controller

            – Kashif
            Mar 27 at 3:44














            i update my model query then it's working for me public function insert_users($data) return $this->db->insert("users",$data); show me true But when i input data from ReactJs form then check localhost/API/UserController/users controller and refresh it then add new record in it in the form of null like that "user_id":"305","UserName":null,"user_email":null,"Password":null,"CreatedDate":"0000-00-00 00:00:00","Status":null,"Role":null,"VendorId":null

            – Kashif
            Mar 27 at 3:51






            i update my model query then it's working for me public function insert_users($data) return $this->db->insert("users",$data); show me true But when i input data from ReactJs form then check localhost/API/UserController/users controller and refresh it then add new record in it in the form of null like that "user_id":"305","UserName":null,"user_email":null,"Password":null,"CreatedDate":"0000-00-00 00:00:00","Status":null,"Role":null,"VendorId":null

            – Kashif
            Mar 27 at 3:51














            If I understand correctly, the insert functionality works fine, but the 'localhost/API/UserController/users' is not showing any result?

            – Femi_DD
            Mar 27 at 5:00





            If I understand correctly, the insert functionality works fine, but the 'localhost/API/UserController/users' is not showing any result?

            – Femi_DD
            Mar 27 at 5:00













            showing result but in the form of null ,like that "user_id":"305","UserName":null,"user_email":null,"Password":null,"CreatedDate":"0000-00-00 00:00:00","Status":null,"Role":null,"VendorId":null

            – Kashif
            Mar 27 at 15:55





            showing result but in the form of null ,like that "user_id":"305","UserName":null,"user_email":null,"Password":null,"CreatedDate":"0000-00-00 00:00:00","Status":null,"Role":null,"VendorId":null

            – Kashif
            Mar 27 at 15:55













            in database data add in the form of null when i input any data using react form new record add in database and also in localhost/API/UserController/users controller

            – Kashif
            Mar 27 at 16:03





            in database data add in the form of null when i input any data using react form new record add in database and also in localhost/API/UserController/users controller

            – Kashif
            Mar 27 at 16:03













            0














            Usermodel



            <?php
            defined('BASEPATH') OR exit('No direct script access allowed');
            class Usermodel extends CI_model

            public function get_users()

            $this->db->where('is_active', 1);
            $query = $this->db->get('users');
            return $query->result();


            public function insert_users($formData)

            $this->db->insert('users', $formData);
            return $this->db->insert_id();




            My UserController Controller in insertUsers Method is:



            <?php
            defined('BASEPATH') OR exit('No direct script access allowed');
            class UserController extends CI_Controller
            public function __construct()

            parent::__construct();
            $this->load->model('Usermodel');


            public function users()

            header("Access-Control-Allow-Origin: *");
            $users = $this->Usermodel->get_users();

            $this->output
            ->set_content_type('application/json')
            ->set_output(json_encode($users));




            public function insertUsers()

            header("Access-Control-Allow-Origin: *");
            header("Access-Control-Request-Headers: GET,POST,OPTIONS,DELETE,PUT");

            $formdata = json_decode(file_get_contents('php://input'), true);

            if( ! empty($formdata))

            $UserName = $formdata['UserName'];
            $user_email = $formdata['user_email'];
            $Password = $formdata['Password'];

            $userData = array(
            'UserName' => $UserName,
            'user_email' => $user_email,
            'Password' => password_hash($Password,PASSWORD_DEFAULT),
            'is_active' => 1,
            'created_at' => date('Y-m-d H', time())
            );

            $id = $this->Usermodel->insert_users($userData);

            $response = array(
            'status' => 'success',
            'message' => 'User Register successfully'
            );

            else
            $response = array(
            'status' => 'error'
            );


            $this->output
            ->set_content_type('application/json')
            ->set_output(json_encode($response));




            Register.js code store data in database now



            import React, Component from 'react';
            import Button, Card, CardBody, CardFooter, Col, Container,Alert, Form, Input, InputGroup, InputGroupAddon, InputGroupText, Row from 'reactstrap';
            class Register extends Component
            constructor(props)
            super(props);
            this.state =
            Username:'',
            user_email:'',
            Password:'',
            error:null,
            response:,

            this.onFormSubmit = this.onFormSubmit.bind(this);
            this.handleChange = this.handleChange.bind(this);
            this.handleSubmit = this.handleSubmit.bind(this);

            handleChange(event)
            const name = event.target.name;
            const value = event.target.value;

            this.setState(
            [name]: value
            );


            handleSubmit=(event)=>
            event.preventDefault();
            this.onFormSubmit(this.state);
            this.setState(this.state);


            onFormSubmit(data)
            const apiUrl = "http://localhost/API/UserController/insertUsers";
            const myHeaders = new Headers();
            myHeaders.append('Content-Type','application/json');
            const options =
            method:'POST',
            body:JSON.stringify(data),
            myHeaders
            ;
            fetch(apiUrl,options)
            .then(res => res.json() )
            .then(result =>
            this.setState(
            response:result,
            );
            )
            .then(error=>
            this.setState(
            error
            );
            );

            this.setState(
            Username:'',
            user_email:'',
            Password:''
            );

            render()
            return (
            <div className="app flex-row align-items-center">
            <Container>
            <Row className="justify-content-center">
            <Col md="9" lg="7" xl="6">
            <Card className="mx-4">
            <CardBody className="p-4">
            <Form onSubmit=this.handleSubmit>
            <h1>Register</h1>
            <p className="text-muted">Create your account</p>
            <InputGroup className="mb-3">
            <InputGroupAddon addonType="prepend">
            <InputGroupText>
            <i className="icon-user"></i>
            </InputGroupText>
            </InputGroupAddon>
            <Input type="text" name="UserName" value=this.state.UserName onChange=this.handleChange placeholder="Username" autoComplete="username" />
            </InputGroup>
            <InputGroup className="mb-3">
            <InputGroupAddon addonType="prepend">
            <InputGroupText>@</InputGroupText>
            </InputGroupAddon>
            <Input type="text" placeholder="User email" name="user_email" value=this.state.user_email onChange=this.handleChange autoComplete="email" />
            </InputGroup>
            <InputGroup className="mb-3">
            <InputGroupAddon addonType="prepend">
            <InputGroupText>
            <i className="icon-lock"></i>
            </InputGroupText>
            </InputGroupAddon>
            <Input type="password" placeholder="Password" value=this.state.Password onChange=this.handleChange name="Password" autoComplete="new-password" />
            </InputGroup>
            <Button color="success" block>Create Account</Button>
            </Form>
            </CardBody>
            <CardFooter className="p-4">
            <Row>
            <Col xs="12" sm="6">
            <Button className="btn-facebook mb-1" block><span>facebook</span></Button>
            </Col>
            <Col xs="12" sm="6">
            <Button className="btn-twitter mb-1" block><span>twitter</span></Button>
            </Col>
            </Row>
            </CardFooter>
            </Card>
            </Col>
            </Row>
            </Container>
            this.state.response.status === 'success' && <div><br /><Alert variant="info">this.state.response.message</Alert></div>
            this.state.error && <div>Error: this.state.error.message</div>
            </div>
            );


            export default Register;





            share|improve this answer





























              0














              Usermodel



              <?php
              defined('BASEPATH') OR exit('No direct script access allowed');
              class Usermodel extends CI_model

              public function get_users()

              $this->db->where('is_active', 1);
              $query = $this->db->get('users');
              return $query->result();


              public function insert_users($formData)

              $this->db->insert('users', $formData);
              return $this->db->insert_id();




              My UserController Controller in insertUsers Method is:



              <?php
              defined('BASEPATH') OR exit('No direct script access allowed');
              class UserController extends CI_Controller
              public function __construct()

              parent::__construct();
              $this->load->model('Usermodel');


              public function users()

              header("Access-Control-Allow-Origin: *");
              $users = $this->Usermodel->get_users();

              $this->output
              ->set_content_type('application/json')
              ->set_output(json_encode($users));




              public function insertUsers()

              header("Access-Control-Allow-Origin: *");
              header("Access-Control-Request-Headers: GET,POST,OPTIONS,DELETE,PUT");

              $formdata = json_decode(file_get_contents('php://input'), true);

              if( ! empty($formdata))

              $UserName = $formdata['UserName'];
              $user_email = $formdata['user_email'];
              $Password = $formdata['Password'];

              $userData = array(
              'UserName' => $UserName,
              'user_email' => $user_email,
              'Password' => password_hash($Password,PASSWORD_DEFAULT),
              'is_active' => 1,
              'created_at' => date('Y-m-d H', time())
              );

              $id = $this->Usermodel->insert_users($userData);

              $response = array(
              'status' => 'success',
              'message' => 'User Register successfully'
              );

              else
              $response = array(
              'status' => 'error'
              );


              $this->output
              ->set_content_type('application/json')
              ->set_output(json_encode($response));




              Register.js code store data in database now



              import React, Component from 'react';
              import Button, Card, CardBody, CardFooter, Col, Container,Alert, Form, Input, InputGroup, InputGroupAddon, InputGroupText, Row from 'reactstrap';
              class Register extends Component
              constructor(props)
              super(props);
              this.state =
              Username:'',
              user_email:'',
              Password:'',
              error:null,
              response:,

              this.onFormSubmit = this.onFormSubmit.bind(this);
              this.handleChange = this.handleChange.bind(this);
              this.handleSubmit = this.handleSubmit.bind(this);

              handleChange(event)
              const name = event.target.name;
              const value = event.target.value;

              this.setState(
              [name]: value
              );


              handleSubmit=(event)=>
              event.preventDefault();
              this.onFormSubmit(this.state);
              this.setState(this.state);


              onFormSubmit(data)
              const apiUrl = "http://localhost/API/UserController/insertUsers";
              const myHeaders = new Headers();
              myHeaders.append('Content-Type','application/json');
              const options =
              method:'POST',
              body:JSON.stringify(data),
              myHeaders
              ;
              fetch(apiUrl,options)
              .then(res => res.json() )
              .then(result =>
              this.setState(
              response:result,
              );
              )
              .then(error=>
              this.setState(
              error
              );
              );

              this.setState(
              Username:'',
              user_email:'',
              Password:''
              );

              render()
              return (
              <div className="app flex-row align-items-center">
              <Container>
              <Row className="justify-content-center">
              <Col md="9" lg="7" xl="6">
              <Card className="mx-4">
              <CardBody className="p-4">
              <Form onSubmit=this.handleSubmit>
              <h1>Register</h1>
              <p className="text-muted">Create your account</p>
              <InputGroup className="mb-3">
              <InputGroupAddon addonType="prepend">
              <InputGroupText>
              <i className="icon-user"></i>
              </InputGroupText>
              </InputGroupAddon>
              <Input type="text" name="UserName" value=this.state.UserName onChange=this.handleChange placeholder="Username" autoComplete="username" />
              </InputGroup>
              <InputGroup className="mb-3">
              <InputGroupAddon addonType="prepend">
              <InputGroupText>@</InputGroupText>
              </InputGroupAddon>
              <Input type="text" placeholder="User email" name="user_email" value=this.state.user_email onChange=this.handleChange autoComplete="email" />
              </InputGroup>
              <InputGroup className="mb-3">
              <InputGroupAddon addonType="prepend">
              <InputGroupText>
              <i className="icon-lock"></i>
              </InputGroupText>
              </InputGroupAddon>
              <Input type="password" placeholder="Password" value=this.state.Password onChange=this.handleChange name="Password" autoComplete="new-password" />
              </InputGroup>
              <Button color="success" block>Create Account</Button>
              </Form>
              </CardBody>
              <CardFooter className="p-4">
              <Row>
              <Col xs="12" sm="6">
              <Button className="btn-facebook mb-1" block><span>facebook</span></Button>
              </Col>
              <Col xs="12" sm="6">
              <Button className="btn-twitter mb-1" block><span>twitter</span></Button>
              </Col>
              </Row>
              </CardFooter>
              </Card>
              </Col>
              </Row>
              </Container>
              this.state.response.status === 'success' && <div><br /><Alert variant="info">this.state.response.message</Alert></div>
              this.state.error && <div>Error: this.state.error.message</div>
              </div>
              );


              export default Register;





              share|improve this answer



























                0












                0








                0







                Usermodel



                <?php
                defined('BASEPATH') OR exit('No direct script access allowed');
                class Usermodel extends CI_model

                public function get_users()

                $this->db->where('is_active', 1);
                $query = $this->db->get('users');
                return $query->result();


                public function insert_users($formData)

                $this->db->insert('users', $formData);
                return $this->db->insert_id();




                My UserController Controller in insertUsers Method is:



                <?php
                defined('BASEPATH') OR exit('No direct script access allowed');
                class UserController extends CI_Controller
                public function __construct()

                parent::__construct();
                $this->load->model('Usermodel');


                public function users()

                header("Access-Control-Allow-Origin: *");
                $users = $this->Usermodel->get_users();

                $this->output
                ->set_content_type('application/json')
                ->set_output(json_encode($users));




                public function insertUsers()

                header("Access-Control-Allow-Origin: *");
                header("Access-Control-Request-Headers: GET,POST,OPTIONS,DELETE,PUT");

                $formdata = json_decode(file_get_contents('php://input'), true);

                if( ! empty($formdata))

                $UserName = $formdata['UserName'];
                $user_email = $formdata['user_email'];
                $Password = $formdata['Password'];

                $userData = array(
                'UserName' => $UserName,
                'user_email' => $user_email,
                'Password' => password_hash($Password,PASSWORD_DEFAULT),
                'is_active' => 1,
                'created_at' => date('Y-m-d H', time())
                );

                $id = $this->Usermodel->insert_users($userData);

                $response = array(
                'status' => 'success',
                'message' => 'User Register successfully'
                );

                else
                $response = array(
                'status' => 'error'
                );


                $this->output
                ->set_content_type('application/json')
                ->set_output(json_encode($response));




                Register.js code store data in database now



                import React, Component from 'react';
                import Button, Card, CardBody, CardFooter, Col, Container,Alert, Form, Input, InputGroup, InputGroupAddon, InputGroupText, Row from 'reactstrap';
                class Register extends Component
                constructor(props)
                super(props);
                this.state =
                Username:'',
                user_email:'',
                Password:'',
                error:null,
                response:,

                this.onFormSubmit = this.onFormSubmit.bind(this);
                this.handleChange = this.handleChange.bind(this);
                this.handleSubmit = this.handleSubmit.bind(this);

                handleChange(event)
                const name = event.target.name;
                const value = event.target.value;

                this.setState(
                [name]: value
                );


                handleSubmit=(event)=>
                event.preventDefault();
                this.onFormSubmit(this.state);
                this.setState(this.state);


                onFormSubmit(data)
                const apiUrl = "http://localhost/API/UserController/insertUsers";
                const myHeaders = new Headers();
                myHeaders.append('Content-Type','application/json');
                const options =
                method:'POST',
                body:JSON.stringify(data),
                myHeaders
                ;
                fetch(apiUrl,options)
                .then(res => res.json() )
                .then(result =>
                this.setState(
                response:result,
                );
                )
                .then(error=>
                this.setState(
                error
                );
                );

                this.setState(
                Username:'',
                user_email:'',
                Password:''
                );

                render()
                return (
                <div className="app flex-row align-items-center">
                <Container>
                <Row className="justify-content-center">
                <Col md="9" lg="7" xl="6">
                <Card className="mx-4">
                <CardBody className="p-4">
                <Form onSubmit=this.handleSubmit>
                <h1>Register</h1>
                <p className="text-muted">Create your account</p>
                <InputGroup className="mb-3">
                <InputGroupAddon addonType="prepend">
                <InputGroupText>
                <i className="icon-user"></i>
                </InputGroupText>
                </InputGroupAddon>
                <Input type="text" name="UserName" value=this.state.UserName onChange=this.handleChange placeholder="Username" autoComplete="username" />
                </InputGroup>
                <InputGroup className="mb-3">
                <InputGroupAddon addonType="prepend">
                <InputGroupText>@</InputGroupText>
                </InputGroupAddon>
                <Input type="text" placeholder="User email" name="user_email" value=this.state.user_email onChange=this.handleChange autoComplete="email" />
                </InputGroup>
                <InputGroup className="mb-3">
                <InputGroupAddon addonType="prepend">
                <InputGroupText>
                <i className="icon-lock"></i>
                </InputGroupText>
                </InputGroupAddon>
                <Input type="password" placeholder="Password" value=this.state.Password onChange=this.handleChange name="Password" autoComplete="new-password" />
                </InputGroup>
                <Button color="success" block>Create Account</Button>
                </Form>
                </CardBody>
                <CardFooter className="p-4">
                <Row>
                <Col xs="12" sm="6">
                <Button className="btn-facebook mb-1" block><span>facebook</span></Button>
                </Col>
                <Col xs="12" sm="6">
                <Button className="btn-twitter mb-1" block><span>twitter</span></Button>
                </Col>
                </Row>
                </CardFooter>
                </Card>
                </Col>
                </Row>
                </Container>
                this.state.response.status === 'success' && <div><br /><Alert variant="info">this.state.response.message</Alert></div>
                this.state.error && <div>Error: this.state.error.message</div>
                </div>
                );


                export default Register;





                share|improve this answer















                Usermodel



                <?php
                defined('BASEPATH') OR exit('No direct script access allowed');
                class Usermodel extends CI_model

                public function get_users()

                $this->db->where('is_active', 1);
                $query = $this->db->get('users');
                return $query->result();


                public function insert_users($formData)

                $this->db->insert('users', $formData);
                return $this->db->insert_id();




                My UserController Controller in insertUsers Method is:



                <?php
                defined('BASEPATH') OR exit('No direct script access allowed');
                class UserController extends CI_Controller
                public function __construct()

                parent::__construct();
                $this->load->model('Usermodel');


                public function users()

                header("Access-Control-Allow-Origin: *");
                $users = $this->Usermodel->get_users();

                $this->output
                ->set_content_type('application/json')
                ->set_output(json_encode($users));




                public function insertUsers()

                header("Access-Control-Allow-Origin: *");
                header("Access-Control-Request-Headers: GET,POST,OPTIONS,DELETE,PUT");

                $formdata = json_decode(file_get_contents('php://input'), true);

                if( ! empty($formdata))

                $UserName = $formdata['UserName'];
                $user_email = $formdata['user_email'];
                $Password = $formdata['Password'];

                $userData = array(
                'UserName' => $UserName,
                'user_email' => $user_email,
                'Password' => password_hash($Password,PASSWORD_DEFAULT),
                'is_active' => 1,
                'created_at' => date('Y-m-d H', time())
                );

                $id = $this->Usermodel->insert_users($userData);

                $response = array(
                'status' => 'success',
                'message' => 'User Register successfully'
                );

                else
                $response = array(
                'status' => 'error'
                );


                $this->output
                ->set_content_type('application/json')
                ->set_output(json_encode($response));




                Register.js code store data in database now



                import React, Component from 'react';
                import Button, Card, CardBody, CardFooter, Col, Container,Alert, Form, Input, InputGroup, InputGroupAddon, InputGroupText, Row from 'reactstrap';
                class Register extends Component
                constructor(props)
                super(props);
                this.state =
                Username:'',
                user_email:'',
                Password:'',
                error:null,
                response:,

                this.onFormSubmit = this.onFormSubmit.bind(this);
                this.handleChange = this.handleChange.bind(this);
                this.handleSubmit = this.handleSubmit.bind(this);

                handleChange(event)
                const name = event.target.name;
                const value = event.target.value;

                this.setState(
                [name]: value
                );


                handleSubmit=(event)=>
                event.preventDefault();
                this.onFormSubmit(this.state);
                this.setState(this.state);


                onFormSubmit(data)
                const apiUrl = "http://localhost/API/UserController/insertUsers";
                const myHeaders = new Headers();
                myHeaders.append('Content-Type','application/json');
                const options =
                method:'POST',
                body:JSON.stringify(data),
                myHeaders
                ;
                fetch(apiUrl,options)
                .then(res => res.json() )
                .then(result =>
                this.setState(
                response:result,
                );
                )
                .then(error=>
                this.setState(
                error
                );
                );

                this.setState(
                Username:'',
                user_email:'',
                Password:''
                );

                render()
                return (
                <div className="app flex-row align-items-center">
                <Container>
                <Row className="justify-content-center">
                <Col md="9" lg="7" xl="6">
                <Card className="mx-4">
                <CardBody className="p-4">
                <Form onSubmit=this.handleSubmit>
                <h1>Register</h1>
                <p className="text-muted">Create your account</p>
                <InputGroup className="mb-3">
                <InputGroupAddon addonType="prepend">
                <InputGroupText>
                <i className="icon-user"></i>
                </InputGroupText>
                </InputGroupAddon>
                <Input type="text" name="UserName" value=this.state.UserName onChange=this.handleChange placeholder="Username" autoComplete="username" />
                </InputGroup>
                <InputGroup className="mb-3">
                <InputGroupAddon addonType="prepend">
                <InputGroupText>@</InputGroupText>
                </InputGroupAddon>
                <Input type="text" placeholder="User email" name="user_email" value=this.state.user_email onChange=this.handleChange autoComplete="email" />
                </InputGroup>
                <InputGroup className="mb-3">
                <InputGroupAddon addonType="prepend">
                <InputGroupText>
                <i className="icon-lock"></i>
                </InputGroupText>
                </InputGroupAddon>
                <Input type="password" placeholder="Password" value=this.state.Password onChange=this.handleChange name="Password" autoComplete="new-password" />
                </InputGroup>
                <Button color="success" block>Create Account</Button>
                </Form>
                </CardBody>
                <CardFooter className="p-4">
                <Row>
                <Col xs="12" sm="6">
                <Button className="btn-facebook mb-1" block><span>facebook</span></Button>
                </Col>
                <Col xs="12" sm="6">
                <Button className="btn-twitter mb-1" block><span>twitter</span></Button>
                </Col>
                </Row>
                </CardFooter>
                </Card>
                </Col>
                </Row>
                </Container>
                this.state.response.status === 'success' && <div><br /><Alert variant="info">this.state.response.message</Alert></div>
                this.state.error && <div>Error: this.state.error.message</div>
                </div>
                );


                export default Register;






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Apr 18 at 14:39

























                answered Apr 18 at 14:34









                KashifKashif

                588




                588



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55310807%2fhow-do-i-avoid-returning-null-data-using-form-in-reactjscheck-back-end-code-als%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해