Im having some issues with my html website

Joined
Jun 4, 2024
Messages
1
Reaction score
0
Im working on website that is linked to phpmyadmin database. the goal of this is to allow users to input data, search the data and display it and delete a record. these records being information for clients. but I'm having issues with the data being inserted into the database using the front end. this is my error.

VM327:1 Uncaught (in promise) SyntaxError: Unexpected token '<', "<br />
<b>"... is not valid JSON

i am using VS code IDE and so far i have 1html file, 1js file, 5php files and a CSS file

HTML is my main interface
js passes the function from PHP to my HTML
my 5php files are:
  • database connection
  • delete function
  • Search function
  • insert function
  • functions (in this one i declared what search, delete and insert do)

i also would like to mention that i am fairly new to programming so i may not understand more advanced terms or simple terms. if you guys want to see my source code i will gladly send it. but please i need assistance with this
 
Joined
Jul 4, 2023
Messages
416
Reaction score
50
Consider using a functions in your php code when entering data that contains html code:

PHP:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $name = htmlentities($_POST['name'], ENT_QUOTES, 'UTF-8');
    $email = htmlentities($_POST['email'], ENT_QUOTES, 'UTF-8');

    $sql = "INSERT INTO clients (name, email) VALUES ('$name', '$email')";

    if ($conn->query($sql) === TRUE) {
        // ...
    }
}

Finally, consider the content of the answer marked as the best in this question from stackoverflow.com:
when to use htmlspecialchars() function?
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,824
Messages
2,569,755
Members
45,744
Latest member
PoppyRizzo

Latest Threads

Top