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

220
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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