html - Node Mysql not inserting -
var mysql = require('mysql'); var url = require('url'); var express = require('express'); var http = require('http'); var app = express(); var aluno, disc; app.get('/', function(req, res){ console.log("aluno: " + req.query.aluno); console.log("disc: " + request.query.disc); }); var connection = mysql.createconnection({ host: "localhost", user: "root", password: "161616", database: "matricula" }); connection.connect(); var post = {iddisciplinasmatriculada: aluno*3+disc*2, iddisciplina: disc, idaluno: aluno}; connection.query('insert disciplinasmatriculadas set ?', post, function(err, result) {});
when change few things can run throught cmd receiving args, when receives "/index.js?aluno=2&disc=2" browser, nothing happens @ db.
does know problem might be?
also, here html file i'm using:
<html> <head> <title>disciplinasmatriculadas</title> <script type="text/javascript"></script> </head> <body style="font-family: sans-serif"> <fieldset> <legend>matricula de aluno em disciplina</legend> id aluno: <input type="text" name="aluno" id="aluno"> <br/> id disciplina: <input type="text" name="disc" id="disc"> <br/> <input type="button" value="add" onclick="adddisciplina();"> </fieldset> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script> <script> function adddisciplina(){ var alunold = $('#aluno').val(); var discold = $('#disc').val(); $.ajax({ url: "http://localhost:80/node/index.js", data: { aluno: alunold, disc: discold} }) .success(function(data){alert('done.');}) .error(function(x,q,h){}); }; </script> </body> </html>
placeholders can represent values. cannot replace sql keywords, field names, table names, operators etc... values only. query must more like
insert ... set fieldname = ?
while not true, consider placeholder equivalent of string literal. version generating amounts to:
insert ... set 'fieldname=?'
that's not assignment operation. it's string characters f
, i
, e
etc... should string put in record? there's no field assign to, it's syntax error.
Comments
Post a Comment