0

I have this request:

var cartes = "SELECT type_carte, classe, date_validite, gare_depart, gare_arrivee, id_client WHERE id_client='" +clcour+ "'";
connection.query(cartes, function(error, lescartes) {
    if (error) {
        console.log(error.message);
    } else {
        console.log('Cartes chargés');
        cartescl = lescartes;
    }
});

but I got a MYSQL SYNTAX ERROR: use near 'WHERE id_client='5' ' at line 1

Any help on why I'm getting this error?

1 Answer 1

1

You have missed the FROM table in the query.

SELECT type_carte, classe, date_validite, gare_depart, gare_arrivee, id_client
FROM your_table
WHERE id_client = ?;

Also consider using prepared statements to mitigate injections. Another issue you might have. WHERE id_client = '5'. I advice you to have IDs as numeric values UNSIGNED INT might be a good start. In that case you should WHERE id_client = 5 (no '). But best is to use prepared statements. Then you don't have to worry at all.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.