【发布时间】:2021-12-22 14:50:00
【问题描述】:
我尝试了很多次,但无法解决这个语法错误。 这是app.js的一个sn-p(起点)
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
});
})
})
这是我插入从数据库接收到的数据的 ejs 文件的 sn-p
<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>
我认为show.ejs中没有语法错误。
【问题讨论】:
-
如果您复制了您收到的确切错误消息并将其粘贴到问题正文的顶部,将会有所帮助。目前该消息仅在问题标题中,并且有点难以阅读,因为我认为您对其进行了一些更改。猜猜它看起来更像这样:
Syntax Error: ')' missing after argument list? -
当
(的数量大于)的数量时会出现这种错误。你在发帖之前至少算过吗? (不计入评论的家长)
标签: javascript mysql node.js express ejs