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

217
Views
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 answers
Answer question

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 Report
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!