bobrown101 2 Newbie Poster

Okay, here's the deal. I have 3 webpages - the first one is a login page with two inputs (for username and password) and a submit button, the 2nd one is a page that requests from the server a list of users, and then displays them on the page, the third one is a page that says that user already exists with a button that sends the user back to webpage 1

I have two questions that need to be answered.

1) I have a simple if statement that verifies that the data the user has submitted does not already exist in the database. If the data is already present, I send the user to webpage 3, and if the data isnt present, then I add the data to the databse and send the user to webpage 2. The problem I have, is I dont know how to generate a request to send the user to webpage 3 if the data already exists.

var collection = db.collection('usercollection');
                collection.find().toArray(function(err, items) {
                    if (userInList(items, data.username)) {

                        //THIS IS WHERE I SEND USER TO *USER ALREADY EXISTS* page

                    }
                    else{
                        console.log('User does not exist, creating now');
                        collection.insert({
                                "username" : data.username,
                                "password" : data.password
                            }, function (err, doc) {
                                if (err) {
                                    // If it failed, return error
                                    console.log("There was a problem adding the information to the database.");
                                }
                                else {
                                    // If it worked
                                    console.log('User added to database: ' + data.username);
                                }
                        });
                    }
                });

2) The 2nd thing that I need to point out, is that on webpage 1, the submit button has an href = "webpage 2". So no matter what, if I click the button, it will send me to webpage 2. However, if the user submits data that already exists and the server would like to send the user to webpage 3, will the button cause problems?

Thank you in advance - Brady

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.