Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Form>
- <div className="form-group">
- <Label for="exampleInputEmail1">Email Address</Label>
- <Input type="email" className="form-control" id="exampleInputEmail1"
- onChange={(event,newValue) => this.setState({email:newValue})}></Input>
- </div>
- <div className="form-group">
- <Label for="example-tel-input">Telephone</Label>
- <Input type="tel" className="form-control" id="example-tel-input"
- onChange = {(event,newValue) => this.setState({phone:newValue})}></Input>
- </div>
- <button type="submit" className="btn btn-primary"
- onClick={(event) => this.handleClick(event)}>Register</button>
- </Form>
- handleClick(event){
- // check for empty values before submitting
- if((this.state.email.length === "") || (this.state.phone.length === "")){
- alert("fields required");
- }else {
- // import sqlite3 module
- const sqlite3 = require('sqlite3').verbose();
- // opening a database connection
- let db = new sqlite3.Database('register.db');
- // creating database table
- db.run('CREATE TABLE users(email phone)');
- // inserting into database
- db.run('INSERT INTO users(email phone) VALUES((?),(?))',function(err){
- if(err){
- return console.log(err.message);
- }
- console.log("row inserted");
- });
- db.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement