title: How to find whether user has signed up before login, in react, node and mariadb
body: <p>I am new to react and mariaDB and this is my first attempt. I have created a sign up and sign in form in a single page. I used reactjs for frontend and node for backend and  used mariaDB as database. I was able to insert username and password to databse when sign up. Now I want to check whether user has signed up when user try to login. I want to display an error as Wrong combination when username and password is not matched with registered users. I tried to display it, but it doesn't work.</p>
  <p>here is my app.js in client side ,</p>
  <pre><code>import React, { useState } from 'react';
  import './App.css';
  import Axios from &quot;axios&quot;;
  function App() {
    const [usernameReg,setUsernameReg]= useState(&quot;&quot;);
    const [passwordReg,setPasswordReg]= useState(&quot;&quot;);
  
  
    const [username,setUsername]= useState(&quot;&quot;);
    const [password,setPassword]= useState(&quot;&quot;);
    const [loginStatus,setLoginStatus]= useState(&quot;&quot;);
  
    const register = () =&gt; {
      
      Axios.post(&quot;http://localhost:3001/register&quot;, {
    
        username:usernameReg,
        password:passwordReg,
      }).then((response) =&gt; {
        console.log(response);
      });
      };
        
      const login = () =&gt; {
      
        Axios.post(&quot;http://localhost:3001/login&quot;, {
      
          username:username,
          password:password,
        }).then((response) =&gt; {
          if(response.data.message){
            setLoginStatus(response.data.message);
          }
          else{
            setLoginStatus(response.data[0].username);
          }
  
        });
        };
  
    return (
      &lt;div className=&quot;App&quot;&gt;
        &lt;div className='registration'&gt;
  
          &lt;label&gt;Username&lt;/label&gt;
          &lt;br/&gt;
          &lt;input type=&quot;text&quot; onChange={(e)=&gt;{
          setUsernameReg(e.target.value)
          }}&gt;
          &lt;/input&gt;
          &lt;br/&gt;
          &lt;label&gt;Password&lt;/label&gt;
          &lt;br/&gt;
          &lt;input type=&quot;text&quot; onChange={(e)=&gt;{
          setPasswordReg(e.target.value)
          }}&gt;
          &lt;/input&gt;
          &lt;br/&gt;
          &lt;button onClick={register}&gt;Register&lt;/button&gt;
          &lt;br/&gt;
        &lt;/div&gt;
        &lt;div className='login'&gt;
  &lt;br/&gt;
          &lt;label&gt;Username&lt;/label&gt;
          &lt;br/&gt;
          &lt;input type=&quot;text&quot;
          onChange={(e)=&gt;{
            setUsername(e.target.value)
            }}
          
          &gt;&lt;/input&gt;
          &lt;br/&gt;
          &lt;label&gt;Password&lt;/label&gt;
          &lt;br/&gt;
          &lt;input type=&quot;text&quot;
          onChange={(e)=&gt;{
            setPassword(e.target.value)
            }}
          
          &gt;&lt;/input&gt;
          &lt;br/&gt;
          &lt;button onClick={login}&gt;Login&lt;/button&gt;
        &lt;/div&gt;
        &lt;h1&gt;{loginStatus}&lt;/h1&gt;
      &lt;/div&gt;
    );
  }
  
  export default App;
  
  
  </code></pre>
  <p>here is my index.js in server side</p>
  <pre><code>const express = require(&quot;express&quot;);
  const mariadb = require(&quot;mariadb&quot;);
  const cors = require(&quot;cors&quot;);
  const bodyParser = require(&quot;body-parser&quot;);
  
  const app = express();
  app.use(cors());
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(express.json());
  
  
  const db = mariadb.createPool({
    user: &quot;root&quot;,
    host: &quot;localhost&quot;,
    password: &quot;NishR&quot;,
    database: &quot;pedro&quot;,
  });
  app.post(&quot;/register&quot;, async (req, res) =&gt; {
   
    
      const username= req.body.username;
      const password = req.body.password;
       db.query(
          &quot;INSERT INTO user (username,PASSWORD) VALUES(?,?)&quot;,
          [username,password],
          (err,result)=&gt;{
              console.log(err);
          }
        );
        
      
    }
    );
    app.post(&quot;/login&quot;, async (req, res) =&gt; {
   
    
      const username= req.body.username;
      const password = req.body.password;
       db.query(
          &quot;SELECT * FROM  user WHERE username=? AND password=?&quot;,
          [username,password],
          (err,result)=&gt;{
              if (err){
              res.send({err:err});
              }
              if(result.length&gt;0){
                  res.send(result);
              }else{
                  res.send({message:&quot;wrong combination&quot;});
              }
          }
        );
        
      
    }
    );
  
  
  
  app.listen(3001, () =&gt; {
      console.log(&quot;Server is running&quot;);
    });
  </code></pre>
  <p>please help me to find the error.</p>