
var mysql = require('mysql');
var moment = require('moment');
var express = require('express');
var app = express();

var con = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : 'root',
  database : 'opp_block'
});

con.connect();

con.query('SELECT day from opp_block_day', function(err, rows, fields) {
 if (!err){
    
    console.log('\nOppBlock days:')
    for (var i in rows) {
      var day = rows[i]["day"];
      console.log('\t'+moment(day).format('dddd MMMM Do, YYYY [at] h:mm'));
    }

  }
  else{
    console.log('Error, are you sure you ran CREATE_DB.sql?');
  }
});

con.end();

var server = app.listen(8080, function () {
  console.log('OppBlock server listening on port %s', server.address().port);
});

@@ -265,367 +265,907 @@
 );%0A%0A
-con.query('SELECT day from opp_block_day', function(err, rows, fields) %7B%0A if (!err)
+//create student if nothing exists in database, update student_info if something does%0Afunction createStudent(studentName, callback) %7B%0A  con.query('SELECT uid_student FROM students WHERE student_info = ?;', %5BstudentName%5D, function(err, results) %7B%0A    if(results%5B0%5D == undefined) 
 %7B%0A    
-%0A
   
-  console.log('%5CnOppBlock days:')%0A    for (var i in rows) %7B%0A      var day = rows%5Bi%5D%5B%22day%22%5D;%0A      console.log('%5Ct'+moment(day).format('dddd MMMM Do, YYYY %5Bat%5D h:mm')
+//if nothing is found in database, create new student%0A      con.query('INSERT INTO students(student_info) VALUES (?);', %5BstudentName%5D, function(result) %7B%0A      callback(result);%0A      %7D);%0A    %7D%0A    else %7B%0A      //if something is found, update student info%0A      con.query('UPDATE students SET student_info = ? WHERE (uid_student = ?);', %5BstudentName, results%5B0%5D.uid_student%5D, function(result) %7B%0A      callback(result
 );%0A
+  
     %7D
-%0A%0A
+);%0A  
   %7D%0A  
-else%7B%0A    console.log('Error, are you sure you ran CREATE_DB.sql?');%0A  %7D%0A%7D);%0A%0Acon.end(
+%7D);%0A%7D%0A/*%0Acalled with%0AcreateStudent(%22name%22, function(res)%7B%0A%0A%7D);%0A*/%0A%0AcreateStudent(%22Conrad Mackethan%22, function(result) %7B%0A%7D);%0A%0AcreateStudent(%22Quint McNeely%22, function(result) %7B%0A%7D
 );%0A%0A
@@ -1286,12 +1286,63 @@
 .port);%0A%7D);%0A
+%0A%0A//TWO FUNCTIONS: ONE FOR .CSV, ONE FOR INDIVIDUAL

create student