The date of posting will always be '0000-00-00 00:00:00'

I'm experiencing an issue with my JavaScript code for writing reviews. Previously, it worked fine, but now the 'datePosted' column consistently outputs the default '0000-00-00 00:00:00'.

writeReview(request, respond) {
        var now = new Date();
        var reviewObject = new Review(null, request.body.reviewUserId, request.body.reviewResId, request.body.review,
            request.body.rating, request.body.numberOfLikes, now.toString());
        var sql = "INSERT INTO resreview.reviews (reviewUserId, reviewResId, review, rating, numberOfLikes, datePosted) VALUES(?,?,?,?,?,?)";

        var values = [reviewObject.getReviewUserId(), reviewObject.getReviewResId(), reviewObject.getReview(),
        reviewObject.getRating(), reviewObject.getNumberOfLikes(), reviewObject.getDatePosted()];
        db.query(sql, values, function (error, result) {
            if (error) {
                throw error;
            }
            else {
                respond.json(result);
            }
        });
    }

This code is from my 'Review.js' file:

"use strict"

class Review {
    constructor(reviewId, reviewUserId, reviewResId, review, rating, numberOfLikes, datePosted) {
        this.reviewId = reviewId;
        this.reviewUserId = reviewUserId;
        this.reviewResId = reviewResId;
        this.review = review;
        this.rating = rating;
        this.numberOfLikes = numberOfLikes;
        this.datePosted = datePosted;
    }
    //add the get methods here
    getReviewId() {
        return this.reviewId;
    }
    getReviewUserId() {
        return this.reviewUserId;
    }
    getReviewResId() {
        return this.reviewResId;
    }
    getReview() {
        return this.review;
    }
    getRating() {
        return this.rating;
    }
    getNumberOfLikes() {
        return this.numberOfLikes;
    }
    getDatePosted() {
        return this.datePosted;
    }
    //id is automatically-incremented
    setReviewId(reviewId) {
        this.reviewId = reviewId;
    }
    setReviewUserId(reviewUserId) {
        this.reviewUserId = reviewUserId;
    }
    setReviewResId(reviewResId) {
        this.reviewResId = reviewResId;
    }
    setReview(review) {
        this.review = review;
    }
    setRating(rating) {
        this.rating = rating;
    }
    setNumberOfLikes(numberOfLikes) {
        this.numberOfLikes = numberOfLikes;
    }
    setDatePosted(datePosted) {
        this.datePosted = datePosted;
    }
}
module.exports = Review;

This is the data being stored in my MySQL database. https://i.sstatic.net/5KvMB.png

After reviewing my previously working files, I couldn't find any issues with the code. Notably, I am not utilizing PHP in this project. The datePosted column in this case uses DATETIME as the datatype, whereas in previous files I used VARCHAR for the same column. Could this difference be causing the issue? Thank you for your assistance!

Answer №1

To handle the date format accurately, consider converting it to mysql datetime per instructions in the comments. Alternatively, if you wish to insert the current date, simply include "Now()" (without quotes) as the value in the sql query itself.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Modify the hover color of <TextField /> within the createMuiTheme() function

Is there a way to change the borderColor on hover for the outlined <TextField /> Component within the createMuiTheme()? I have managed to do it easily for the underlined <Input /> export default createMuiTheme({ MuiInput: { &apo ...

Access the value retrieved from a form on the previous page using PHP

I'm struggling with extracting values from radio buttons on a previous page. Currently, my HTML and PHP code works fine with the search bar, which is the first form below. However, I'd like to add radio button filters below the search bar. <s ...

Transfer information from one Angular JS page to another pager based on ID

In my use of the mobile angular js UI framework, I am a beginner in angular js and looking to transmit data from one page to another using city id. When a user clicks on a city, the data should be displayed according to that specific city. HOME PAGE: ht ...

"Troubleshooting: Ajax File Uploader Plugin Not Functioning Properly

Today, our web site's file upload feature using the javascript plugin Simple-ajax-uploader suddenly stopped functioning (09/05/2019). The upload div/button is unresponsive when clicked. This issue is not limited to our site; even the official plugin ...

Error 1064: Oops! There seems to be a mistake in your SQL syntax. Take a look at the user manual for your current version of MySQL server to find the correct syntax near '(partit'

There seems to be an issue with the query... #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(partition by chiti order by rcvddate desc) from received LIMIT ...

Exploring ES6 classes in Java Script: accessing prototype properties

After searching extensively for an answer and coming up empty-handed, I decided to pose my question here. When creating an object constructor in JavaScript as shown below: function Car(speed){ this.speed = speed; this.position = 0; } Car.prototype.m ...

Filtering Database Tables

UPDATE: Apologies for my lack of familiarity with the guidelines as a newcomer here. Here is my progress so far: <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>AJAX filter demo</title> </head> < ...

A dedicated folder for hosting the static assets generated by Nuxt.js

I have a quick question I'm looking to create a dedicated directory for the static files generated by Nuxt Js Currently, Nuxt Js compiles all files into a single directory called 'dist' As I am utilizing Django Server as my backend, I nee ...

"Experience random updates in the priv/static/js/app.js file whenever changes are made to Vue files in the Phoenix/Elixir/V

I have a vue.js/Phoenix application and I am currently facing a challenge with configuring the frontend assets properly. I have noticed that my priv/static/js/app.js file keeps updating whenever I make changes in other files, and I am unable to understand ...

determine if the req.params parameter is void on an express route

Hi everyone, I'm a beginner with node and express and could really use some guidance. I am currently attempting to create a get request that checks if the req.params.address_line is empty, and then performs an action based on that condition. However, ...

Is it possible to update the CSS file of an external SVG file in real-time?

Is there a way for an SVG image to reference another CSS file? A webpage contains an SVG file. A button allows users to switch between classic colors and high contrast mode on the entire webpage, including the SVG image. Attempt w.css (white backgrou ...

Using React hooks and Typescript: I was expecting to see an assignment or function call, but instead, an expression was

After working as a React developer for quite some time, my workplace recently introduced Typescript, which I am still getting familiar with. I implemented a custom hook for managing cookies, but the function it returns is generating an error. Here's ...

Struggling with slow loading times for Three.JS GLTF models? Discover ways to optimize and speed up the load time

My GLTF model (9mb) is loading slowly in ThreeJS. It takes about 4-5 seconds to load on my PC and around 11 seconds on my iPhone. I'm looking for ways to speed up the rendering times. Surprisingly, examples from the ThreeJS website load faster than my ...

Exploring client-server relationships within the Express framework

Is there a way to transfer an object to JavaScript on the client side? I previously asked this question and received an answer, but because I was unable to check it on my computer, I accepted the response. You can view the details here: Client receive jso ...

php$insert new field into mysql table using form insertcell

How do I insert a column in MySQL? I am struggling with the insertCell form. I have tried but I can't seem to add a MySQL column using my JavaScript code with PHP. I am familiar with Php PDO, but this seems difficult to me. Can someone guide me on ho ...

What is the best method for transforming a stream into a file with AngularJS?

Currently, I have a server returning a file stream (StreamingOutput). My goal is to convert this file stream into an actual file using AngularJS, javascript, JQuery, or any other relevant libraries. I am looking to display the file in a <div> or ano ...

Conceal an item if it is located past a certain point (from the viewpoint of the camera)

In the realm of three-dimensional space, imagine a cube represented by a THREE.Mesh that has been added to the scene. cube.position.set( 10, 10, 10 ); scene.add( cube ); Once you have rotated the scene using your mouse, the goal is to cleverly conceal th ...

Tips for Updating Information within a Table with the Help of jQuery, AJAX, PHP, and MySQL

I need some assistance! Here's the scenario: There are two tables containing data from the database. The number of tables varies based on the user posting them. I utilized a "while loop" to display the table with data on the page. Now, I want the d ...

Verify whether the external JavaScript file has already been loaded

After a successful ajax request, I am loading a script using the following code: $.getScript(base_url + 'js/js_to_be_loaded.js'); Is there a way for me to check if that specific script has already been loaded? Thank you. ...

Guide on sequentially inserting data into database columns using PHP

I am facing a situation where I need to insert data into three columns using PHP. The code will be executed three times. When running the code for the first time, I want to insert data only into column1, leaving the other columns empty. For the second ex ...