Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

240
Visualizações
¿Cómo puedo tomar la entrada de un servidor nodjs y ponerla en una base de datos MySql?

Entonces tengo la ruta api aquí donde podemos agregar un usuario a mi servidor

 @app.route('/api/adduser', methods = ['POST']) # This is a post method because the user needs to be able to add info def adding_stuff(): request_data = request.get_json() # Gets the info from the table and converts to JSON format new_fname = request_data['firstname'] new_lname = request_data['lastname'] conn = create_connection("", "", "", "") sql = "INSERT INTO restaurantusers (firstname, lastname) VALUES ('%s', '%s');" % (new_fname, new_lname) # This sql statement will then be uploaded to the databse to add a new record execute_query(conn, sql) # This will execute the query return 'Post worked'

Luego tengo un servidor NodeJs ejecutándose con la API que se selecciona cuando se completa el formulario

 app.post('/add_people', function(req, res){ axios.get('http://127.0.0.1:5000/api/adduser') .then((response)=>{ var restlist = response.data.results; console.log(restlist); // Now we will execute the results in the page named thanks }); });

Por último, el formulario se ve así

 <form action="/add_user" method="post"> <input type = "text" firstname = "firstname"> <input type="submit" class="btn btn-primary"> <h1>Lets add our last name </h1> <form action="/add_user" method="post"> <input type = "text" lastname = "lastname"> <input type="submit" class="btn btn-primary"> </form>

¿Qué falta o qué puedo agregar para que el usuario realmente se agregue al servidor?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda