javascript - Delete row on website using Node js -
i'm working node js, building app school project, pictures has been uploaded, edited , deleted mysql database. i've managed upload page, pictures can edit, can't succeed delete query. on webpage user has press delete button delete picture row data driver, team, etc. code:
index.ejs
<% if(pictures.length){ %> <table style="width:100%"> <tr> <th>image</th> <th>driver</th> <th>team</th> <th>location</th> <% if(admin) { %> <th>edit</th> <th>delete</th> <% } %> </tr> <% } %> <% (var = 0; < pictures.length; i++) { %> <tr> <td><img src="images/<%= pictures[i].image %>" /></td> <td><%= pictures[i].driver %></td> <td><%= pictures[i].team %></td> <td><%= pictures[i].location %></td> <% if(admin) { %> <td><a href="/edit/<%= pictures[i].id %>" >edit</a></td> <td><a href="/edit/delete/<%= pictures[i].id %>">delete</a></td> <% } %> <% } %> </tr> </table> </div>
edit.js
router.get('/delete/:id', function(req, res) { var id = req.params.id; req.getconnection(function (err, connection) { connection.query("delete pictures id = ? ", [id], function(err, results) { res.redirect('/'); console.log('some data has been deleted') }); }); });
app.js
var express = require('express'), path = require('path'), session = require('express-session'), bodyparser = require('body-parser'), // anders kan er geen post worden gebruikt, de post zit in de body mysql = require('mysql'), myconnection = require('express-myconnection'); // set de database var dboptions = { host: 'localhost', user: 'fcdeen_user', password: 'wevgt9ctm8kuxdtd', database: 'fcdeen' }; // definieer de routers var indexroutes = require('./routes/index'), loginroutes = require('./routes/login'), uploadroutes = require('./routes/upload'), editroutes = require('./routes/edit'); // applicatie wordt aangemaakt var app = express(); // gebruik de session app.use(session({ secret: "its_a_very_dark_secret", resave: false, saveuninitialized: true })); // voeg de bodyparser middleware aan de app toe, handelt de post requests af app.use(bodyparser.json()); app.use(bodyparser.urlencoded({extended: true})); // voeg connectie middleware toe aan app app.use(myconnection(mysql, dboptions, 'single')); // set de view engine op ejs app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs'); // hierdoor weet express welke static file er gebruikt moet worden app.use(express.static('public')); // verbind de routers met de routes app.use('/', indexroutes); app.use('/login', loginroutes); app.use('/upload', uploadroutes); app.use('/edit', editroutes); app.get('/', function(req, res) { res.render('index'); }); // start de server, app luistert naar poort 8080 app.listen(8080); console.log('launch @ port 8080');
when press delete button, error:
cannot /10 (10 id of row want delete)
Comments
Post a Comment