Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
¿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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!