Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

219
Vistas
Syntax Error : )missing after argument list in the ejs file

I have tried many times but cannot resolve this syntax error. This is a snippet of the app.js(the starting point)

const express = require('express');
const sql = require('mysql');
const ejs = require('ejs');

const app = express();

app.set('view-engine','ejs');
app.use(express.urlencoded({extended: false}));



const db = sql.createConnection({
    host: 'localhost',
    user: 'root',
    password: '',
    database: 'assignment'
});

db.connect((err) => {
    if (err)
        throw err;
    console.log('Mole in');
});


app.get('/show',(req,res) => {
    let sql = 'SELECT * FROM info';
    let query = db.query(sql,(err,result) => {
        if(err) throw err;
        console.log(result,result.length);
        res.render('show.ejs',{
            students : result
        });
    })    
})

This is the snippet of the ejs file where I am inserting the data that I have received from the database

<tbody>
                <%
                students.forEach((student)=> {
                %>
                    <tr>
                        <td><%=student['Name'] %></td>
                        <td><%=student['Age'] %></td>
                        <td><%=student['Gender'] %></td>
                        <td><%=student['Course'] %></td>
                        <td><%=student['Email'] %></td>
                        <td><%=student['Studentid'] %></td>
                        <td><%=student["Marks 1"] %></td>
                        <td><%=student["Marks 2"] %></td>
                        <td><%=student["Marks 3"] %></td>
                        <td><%=student["Marks 4"] %></td>
                        <td><%=student["Marks 5"] %></td>
                        <td>
                            <button class = "btn btn-outline-danger">Edit</button>
                            <button class = "btn btn-outline-danger">Delete</button>
                        </td>
                    </tr>
                <% }); %>
            </tbody>

I think there is no syntax error here in show.ejs.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The error is because you used js code outside ejs syntax. Also, since forEach has a single argument you dont have to wrap it with brackets.

<tbody>
                <% students.forEach(student => {%>
                    <tr>
                        <td><%=student['Name'] %></td>
                        <td><%=student['Age'] %></td>
                        <td><%=student['Gender'] %></td>
                        <td><%=student['Course'] %></td>
                        <td><%=student['Email'] %></td>
                        <td><%=student['Studentid'] %></td>
                        <td><%=student["Marks 1"] %></td>
                        <td><%=student["Marks 2"] %></td>
                        <td><%=student["Marks 3"] %></td>
                        <td><%=student["Marks 4"] %></td>
                        <td><%=student["Marks 5"] %></td>
                        <td>
                            <button class = "btn btn-outline-danger">Edit</button>
                            <button class = "btn btn-outline-danger">Delete</button>
                        </td>
                    </tr>
                <% }); %>
            </tbody>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda